若依定制pdf生成實戰

一、介紹

使用 Java Apache POI 將文字渲染到 Word 模板是一種常見的文檔自動化技術,廣泛應用于批量生成或定制 Word 文檔的場景。使用aspose可以將word轉成pdf從而達到定制化pdf的目的。

參考文檔:java實現Word轉Pdf(Windows、Linux通用) - 故城歸人 - 博客園

二、word模板準備

(1)pdf逆轉

本次實踐沒有word模板,需從生成的pdf先還原成word。所以使用python將pdf逆轉成word docx:

!pip install pdf2docxfrom pdf2docx import Converter
pdf_file = '專業技術資格評審申報表_預覽.pdf'
docx_file = '申報表模板.docx'
cv = Converter(pdf_file)
#cv.convert(docx_file, start=0, end=2)  # 只轉前三頁
cv.convert(docx_file)# 轉全部
cv.close()

創建word模板,在其中插入占位符,例如 {{name}}、{{workorg}}

(2)模版讀取方式

? ?絕對路徑讀取:缺點路徑變化無法讀出

String baseDir = System.getProperty("user.dir");//獲取項目根目錄
String templatePath = baseDir + "/peer-upms/peer-upms-biz/src/main/resources/file/title_template.docx";
File templateFile = new File(templatePath);

? ?classpath讀取:這樣就不再依賴項目根目錄的絕對路徑,打包之后只要 title_template.docx 在 src/main/resources/file/ 下,就能自動被拷貝并使用。之后你再用 templateFile 打開 POI 進行替換就能正常運行了。

// 1. 從 classpath 加載模板資源(src/main/resources/file/title_template.docx)
ClassPathResource tplRes = new ClassPathResource("file/title_template.docx");
if (!tplRes.exists()) {throw new FileNotFoundException("classpath:/file/title_template.docx 不存在");
}// 2. 將模板復制到一個臨時文件(因為 POI 需要 File)
File templateFile = File.createTempFile("title_cover_", ".docx");
try (InputStream in = tplRes.getInputStream();FileOutputStream out = new FileOutputStream(templateFile)) {in.transferTo(out);}

三、Java相關代碼

word部分(渲染數據寫死)

(1)引入依賴:

   <dependency><groupId>cn.afterturn</groupId><artifactId>easypoi-base</artifactId><version>4.1.0</version><scope>compile</scope></dependency>

(2)word下載接口:

 @Operation(summary = "申請人DOCX下載",responses = {@ApiResponse(responseCode = "200",content = @Content(mediaType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document",schema = @Schema(type = "string", format = "binary")))})@RequestMapping(value = "/download/docx", method = RequestMethod.GET)public ResponseEntity<Resource> downloadDocx() {Map<String, Object> data = new HashMap<>();data.put("name", "XX1");data.put("department", "XX111測試");data.put("zhuanye", "作物育種");data.put("jishuzige", "研究員");data.put("nian", "2025");data.put("yue", "03");data.put("ri", "20");data.put("datetime", "2025/03/20 14:11:44");data.put("zhuanyejishu", "生命科學研究");try {File docxFile = wordToPdfService.generateDocx(data);File file = new File(docxFile.getName());if (!file.exists()) {return ResponseEntity.notFound().build();}Resource resource = new FileSystemResource(file);if (!resource.exists() || !resource.isReadable()) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();}HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.wordprocessingml.document"));String fileName = "專業技術資格申報表_" + data.get("name") + "_預覽.docx";
//            headers.setContentDisposition(ContentDisposition.builder("attachment").filename(fileName).build());//解決中文亂碼問題ContentDisposition contentDisposition = ContentDisposition.builder("attachment").filename(fileName, StandardCharsets.UTF_8).build();headers.setContentDisposition(contentDisposition);headers.setContentLength(file.length());return new ResponseEntity<>(resource, headers, HttpStatus.OK);} catch (Exception e) {e.printStackTrace();return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();}}
@Service
public class WordToPdfService {/**** 根據word模板生成word文檔**/public File generateDocx(Map<String, Object> data) throws Exception {String baseDir = System.getProperty("user.dir");String templatePath = baseDir + "/peer-upms/peer-upms-biz/src/main/resources/file/title_template.docx";File templateFile = new File(templatePath);if (!templateFile.exists()) {throw new Exception("Template file does not exist at: " + templatePath);}try (FileInputStream fis = new FileInputStream(templateFile)) {if (fis.available() <= 0) {throw new Exception("Template file is empty.");}}XWPFDocument document = WordExportUtil.exportWord07(templatePath, data);try (FileOutputStream fos = new FileOutputStream("output.docx")) {document.write(fos);}File docxFile = new File("output.docx");return docxFile;}
......

pdf部分(渲染數據從mysql中拉取)

(1) 引入jar包:

mvn install:install-file   -Dfile=peer-upms/peer-upms-biz/libs/aspose-words-15.8.0-jdk16.jar   -DgroupId=com.aspose   -DartifactId=aspose-words   -Dversion=15.8.0-jdk16   -Dpackaging=jar

(2)下載pdf接口(先轉word再生成對應的pdf)


@Inner(value = false)
@RestController
@RequiredArgsConstructor
public class TitlePdfDownloadController {@Autowiredprivate ApplyDataPdfPreviewService applyDataPdfPreviewService;@GetMapping(value = "/downloadPdf")@Inner(value = false)public ResponseEntity<Resource> downloadWord() {try {Map<String, Object> data = new HashMap<>();data = applyDataPdfPreviewService.getDataByApplyId(applyId);// 1. Generate DOCX fileFile docxFile = wordToPdfService.generateDocx(data);// 2. Convert DOCX to PDFFile pdfFile = wordToPdfService.convertDocxToPdf(docxFile);// 3. Read PDF file bytesbyte[] pdfBytes = Files.readAllBytes(pdfFile.toPath());// 4. Set file name and response headers with PDF MIME typeString fileName = "專業技術資格申報表_" + data.get("name") + "_" + "預覽.pdf";Resource resource = new ByteArrayResource(pdfBytes);HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_PDF);headers.setContentDispositionFormData("attachment", fileName);headers.setContentLength(pdfBytes.length);return new ResponseEntity<>(resource, headers, HttpStatus.OK);} catch (Exception e) {e.printStackTrace();return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();}}

(3)將動態從mysql獲取數據寫成一個service:


@Service
public class ApplyDataPdfPreviewService {@Autowiredprivate JdbcTemplate jdbcTemplate;@Autowiredprivate FindCitiidMapper findCitiidMapper;/*** 根據 applyId 拉取申報表、學歷和獎懲信息,* 并組裝到一個 Map 中返回。*/public Map<String,Object> getDataByApplyId(long applyId) {Map<String,Object> data = new HashMap<>();// 0)拉取 title_apply_applypers 中的mobile字段String citiid = findCitiidMapper.findCitiidByApplyId(applyId);String sqlMobile = "select mobile from title_apply_applypers where citiid=?";Map<String,Object> mobile = jdbcTemplate.queryForMap(sqlMobile, citiid);data.put("mobile", mobile.get("mobile"));// 1) 拉取 title_applytable 中的所有字段String sqlMain = """SELECTexctypecd,techqualtype_cd,citiid,name,workorg,gend_cd,birthday,job_dt,presdivtechjob,discactisitu,presdivtechpost,presdivtechpostbgn_tm,apply_id,apply_serie_nm,applydiv_nm,prestechqual_nm,fillin_tm,perm_nm,permget_tm,permcertnum,divtype,prestechqualget_tm,prestechqualapprorg_nm,presdivtechjobbyear,applytechqualdetail_cd,innovationteamFROM title_applytableWHERE apply_id = ?""";Map<String,Object> main = jdbcTemplate.queryForMap(sqlMain, applyId);// 基本字段放入 mapString exctypecd = main.get("exctypecd").toString();switch (exctypecd) {case "1":data.put("c1",                 "√");data.put("c2",                 " ");data.put("c3",                 " ");data.put("c4",                 " ");break;case "2":data.put("c1",                 " ");data.put("c2",                 "√");data.put("c3",                 " ");data.put("c4",                 " ");break;case "5":data.put("c1",                 " ");data.put("c2",                 " ");data.put("c3",                 "√");data.put("c4",                 " ");break;case "6":data.put("c1",                 " ");data.put("c2",                 " ");data.put("c3",                 " ");data.put("c4",                 "√");break;default:data.put("c1",                 " ");data.put("c2",                 " ");data.put("c3",                 " ");data.put("c4",                 " ");break;}String techqualtype_cd = main.get("techqualtype_cd").toString();String techType ="";switch (techqualtype_cd) {case "1":techType = "應用基礎研究與技術開發人員";break;case "2":techType = "試驗發展與轉化應用人員";break;case "3":techType = "農業政策與科技管理研究人員";break;default:techType = "";break;}data.put("techType",                techType);......// 2) 拉取學歷信息列表String sqlEdu = """SELECTschool_nm,edu_nm,edutype_cd,edu_cd,digree_cd,gradsitu_cd,edubegin_tm,grad_tmFROM title_edurecWHERE apply_id = ?ORDER BY edubegin_tm""";List<Map<String,Object>> edus = jdbcTemplate.queryForList(sqlEdu, applyId);for (int i = 0; i < 4; i++) {Map<String,Object> e = i < edus.size() ? edus.get(i) : new HashMap<>();int idx = i + 1;data.put("school_nm" + idx,    e.get("school_nm") != null ? e.get("school_nm") : " ");data.put("edu_nm" + idx,       e.get("edu_nm") != null ? e.get("edu_nm") : " ");data.put("edutype_cd" + idx,   e.get("edutype_cd") != null ? e.get("edutype_cd") : " ");data.put("edu_cd" + idx,       e.get("edu_cd") != null ? e.get("edu_cd") : " ");data.put("digree_cd" + idx,    e.get("digree_cd") != null ? e.get("digree_cd") : " ");data.put("gradsitu_cd" + idx,  e.get("gradsitu_cd") != null ? e.get("gradsitu_cd") : " ");data.put("edubegin_tm" + idx,  e.get("edubegin_tm") != null ? e.get("edubegin_tm") : " ");data.put("grad_tm" + idx,      e.get("grad_tm") != null ? e.get("grad_tm") : " ");}// 3) 拉取獎懲信息列表String sqlBonus = """SELECTbonus_nm,bonus_tm,bonusorgFROM title_bonusWHERE apply_id = ?ORDER BY bonus_tm DESC""";List<Map<String,Object>> bonuses = jdbcTemplate.queryForList(sqlBonus, applyId);for (int i = 0; i < 3; i++) {Map<String,Object> b = i < bonuses.size()  ? bonuses.get(i) : new HashMap<>();int idx = i + 1;data.put("bonus_nm" + idx, b.size() != 0 ? b.get("bonus_nm") : " ");data.put("bonus_tm" + idx, b.size() != 0  ? b.get("bonus_tm") : " ");data.put("bonusorg" + idx, b.size() != 0 ? b.get("bonusorg") : " ");}data.put("nian", java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy")));data.put("yue", java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("MM")));data.put("ri", java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("dd")));data.put("print_time", java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));// 4) 繼續教育情況String sqlContEdu = """SELECT begin_tm, end_tm, content, chargorg, studyaddrFROM title_applycontedusituWHERE apply_id = ?ORDER BY begin_tm""";List<Map<String,Object>> contEdus = jdbcTemplate.queryForList(sqlContEdu, applyId);for (int i = 0; i < 4; i++) {Map<String,Object> ce = i < contEdus.size() ? contEdus.get(i) : new HashMap<>();int idx = i + 1;data.put("cont_b" + idx, ce.size() != 0 ? ce.get("begin_tm") : " ");data.put("cont_e" + idx, ce.size() != 0 ? ce.get("end_tm") : " ");data.put("content" + idx, ce.size() != 0 ? ce.get("content") : " ");data.put("contedu_char" + idx, ce.size() != 0 ? ce.get("chargorg") : " ");data.put("caddr" + idx, ce.size() != 0 ? ce.get("studyaddr") : " ");}// 5) 專業考試成績情況String sqlExam = """SELECT exam_tm, org, project, score, qualifycodeFROM title_professionalexaminfoWHERE apply_id = ?ORDER BY exam_tm""";List<Map<String,Object>> exams = jdbcTemplate.queryForList(sqlExam, applyId);for (int i = 0; i < 4; i++) {Map<String,Object> ex = i < exams.size() ? exams.get(i) : new HashMap<>();int idx = i + 1;data.put("exam_tm" + idx, ex.size() != 0 ? ex.get("exam_tm") : " ");data.put("exam_org" + idx, ex.size() != 0 ? ex.get("org") : " ");data.put("exam_project" + idx, ex.size() != 0 ? ex.get("project") : " ");data.put("escore" + idx, ex.size() != 0 ? ex.get("score") : " ");data.put("exam_qualifycode" + idx, ex.size() != 0 ? ex.get("qualifycode") : " ");}// 6) 工作經歷String sqlWork = """SELECT begin_tm, end_tm, workposi, workcont, postFROM title_workresuWHERE apply_id = ?ORDER BY begin_tm""";List<Map<String,Object>> works = jdbcTemplate.queryForList(sqlWork, applyId);for (int i = 0; i < 4; i++) {Map<String, Object> w = i < works.size() ? works.get(i) : new HashMap<>();int idx = i + 1;data.put("workresu_begin" + idx, w.size() != 0 ? w.get("begin_tm") : " ");data.put("workresu_end" + idx, w.size() != 0 ? w.get("end_tm") : " ");data.put("workresu_workposi" + idx, w.size() != 0 ? w.get("workposi") : " ");data.put("workresu_workcont" + idx, w.size() != 0 ? w.get("workcont") : " ");data.put("workresu_post" + idx, w.size() != 0 ? w.get("post") : " ");}// 7) 著作、論文及報告登記String sqlArticle = """SELECT artititle, publorg, charorg, volumes, publish_time, persdutyFROM title_applyarticleWHERE apply_id = ?ORDER BY publish_time""";List<Map<String,Object>> articles = jdbcTemplate.queryForList(sqlArticle, applyId);for (int i = 0; i < 4; i++) {Map<String, Object> w = i < articles.size() ? articles.get(i) : new HashMap<>();int idx = i + 1;data.put("article_artititle" + idx, !w.isEmpty() ? w.get("artititle") : " ");data.put("article_publorg" + idx, !w.isEmpty() ? w.get("publorg") : " ");data.put("article_charorg" + idx, !w.isEmpty() ? w.get("charorg") : " ");data.put("article_volumes" + idx, !w.isEmpty() ? w.get("volumes") : " ");data.put("article_publish_time" + idx, !w.isEmpty() ? w.get("publish_time") : " ");data.put("article_persduty" + idx, !w.isEmpty() ? w.get("persduty") : " ");}// 8) 任現職以來考核情況String sqlAssess = """SELECT year, divtechpost, asserslt, asseorg, remarkFROM title_applyassesituWHERE apply_id = ?ORDER BY year""";List<Map<String,Object>> assesses = jdbcTemplate.queryForList(sqlAssess, applyId);for (int i = 0; i < 4; i++) {Map<String, Object> as = i < assesses.size() ? assesses.get(i) : new HashMap<>();int idx = i + 1;data.put("assess_year"        + idx, !as.isEmpty() ? as.get("year") : " ");data.put("assess_divtechpost" + idx, !as.isEmpty() ? as.get("divtechpost") : " ");data.put("assess_asserslt"    + idx, !as.isEmpty() ? as.get("asserslt") : " ");data.put("assess_asseorg"     + idx, !as.isEmpty() ? as.get("asseorg") : " ");data.put("assess_remark"      + idx, !as.isEmpty() ? as.get("remark") : " ");}// 9) 工作總結(單值)String sqlSumm = """SELECT presjobsummFROM title_applytableWHERE apply_id = ?""";String summary = jdbcTemplate.queryForObject(sqlSumm, String.class, applyId);data.put("presjobsumm", summary);return data;}

(4)使用aspose將word轉pdf

 /*** 商業版pdf許可 license,從 classpath 下讀取 license.xml*/public static boolean getLicense() {boolean result = false;InputStream is = null;try {Resource resource = new ClassPathResource("license.xml");is = resource.getInputStream();License aposeLic = new License();aposeLic.setLicense(is);result = true;} catch (Exception e) {e.printStackTrace();}finally {if (is != null) {try {is.close();} catch (IOException e) {e.printStackTrace();}}}return result;}/*** 將傳入的 DOCX 文件轉換成帶完整樣式的 PDF 并返回該 File。** @param docxFile  Word 模板(已填充占位符)的 File* @return           生成的 PDF 臨時文件* @throws Exception 轉換失敗時拋出*/public File convertDocxToPdf(File docxFile, long applyId) throws Exception {getLicense(); // 驗證License 若不驗證則轉化出的pdf文檔會有水印產生// 1. 構造輸出 PDF 的臨時文件String uuid = IdUtil.simpleUUID();String fileName = uuid+".pdf";Path targetPath = Paths.get(fileLocalPath, "PreviewPdf", fileName);File pdfFile = new File(targetPath.toString());pdfFile.getParentFile().mkdirs();TitleApplyApplydataappe applyDataAppe = new TitleApplyApplydataappe();applyDataAppe.setApplyId(applyId);applyDataAppe.setAppefile(fileName);applyDataAppe.setFilesize(pdfFile.length());applyDataAppe.setAppefiledispnm("專業技術資格申報表預覽_"+applyId+".pdf");applyDataAppe.setOpTm(LocalDateTime.now());applyDataAppe.setDir("PreviewPdf");titleApplyApplydataappeService.save(applyDataAppe);// 使用商業破解版 Aspose.Words 完成轉換try (FileOutputStream os = new FileOutputStream(pdfFile)) {// Document 可以直接接收 File 或 String 路徑Document doc = new Document(docxFile.getAbsolutePath());doc.save(os, SaveFormat.PDF);}return pdfFile;}

四、部署

單體后端jar包部署

docker run -d --name peer-boot   -v $PWD/peer-boot.jar:/app/peer-boot.jar -v /usr/share/fonts:/usr/share/fonts   --net host   eclipse-temurin:17-jdk   java -Dfile.encoding=utf-8 -jar /app/peer-boot.jar

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/79587.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/79587.shtml
英文地址,請注明出處:http://en.pswp.cn/web/79587.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Redis再次開源!reids8.0.0一鍵安裝腳本分享

準備工作 1. 下載 Redis 8 安裝包 # Redis 8.0.0 示例&#xff08;請替換為實際版本&#xff09; http://download.redis.io/releases/redis-8.0.0.tar.gz一、腳本內容&#xff1a; #!/usr/bin/python # -*- coding: UTF-8 -*-import os import time import shutil import s…

stm32之BKP備份寄存器和RTC時鐘

目錄 1.時間戳1.1 Unix時間戳1.2 UTC/GMT1.3 時間戳轉換**1.** time_t time(time_t*)**2.** struct tm* gmtime(const time_t*)**3.** struct tm* localtime(const time_t*)**4.** time_t mktime(struct tm*)**5.** char* ctime(const time_t*)**6.** char* asctime(const stru…

Android學習總結之算法篇八(二叉樹和數組)

路徑總和 import java.util.ArrayList; import java.util.List;// 定義二叉樹節點類 class TreeNode {int val;TreeNode left;TreeNode right;// 構造函數&#xff0c;用于初始化節點值TreeNode(int x) {val x;} }public class PathSumProblems {// 路徑總和 I&#xff1a;判…

Scala和Spark的介紹

Scala 1. Slaca的發展過程 由洛桑聯邦理工學院的馬丁 奧德斯在 2001 年基于 Funnel 的工作開始設計&#xff0c;設計初衷是想集成面向對象編程和函數式編程的各種特性。 Scala 是一種純粹的面向對象的語言&#xff0c;每個值都是對象。 Scala 也是一種函數式語言&#xff0…

配置Hadoop集群環境-使用腳本命令實現集群文件同步

在 Hadoop 集群環境中&#xff0c;確保各節點配置文件一致至關重要。以下是使用 rsync 結合 SSH 實現集群文件同步的腳本方案&#xff0c;支持批量同步文件到所有節點&#xff1a; 1. 前提條件 所有節點已配置 SSH 免密登錄主節點&#xff08;NameNode&#xff09;能通過主機…

Redis能保證數據不丟失嗎之RDB

有了AOF為什么還需要RDB? 上一篇我們介紹了Redis AOF持久化策略。Redis能保證數據不丟失嗎之AOF AOF雖然能實現持久化,但由于AOF恢復數據的時候是一條一條命令重新執行的,但數據量大的時候,Redis數據恢復的時間就會很久,這會導致Redis在重啟的時候,有一大段時間的不可用…

AI浪潮下的藝術突圍戰:對話《名人百科數據庫》執行主編劉鑫煒

當AI生成的畫作在國際賽事中摘冠&#xff0c;當算法推薦主導藝術傳播路徑&#xff0c;技術革命正以前所未有的速度重塑藝術生態。我們獨家專訪深耕藝術推廣領域的劉鑫煒主編&#xff0c;探討當代藝術家在智能時代的生存法則。 圖為《名人百科數據庫》執行主編劉鑫煒 技術重構創…

Python 實現失敗重試功能的幾種方法

更多內容請見: python3案例和總結-專欄介紹和目錄 文章目錄 方法 1:手動 `while` 循環 + 異常捕獲方法 2:使用 `tenacity` 庫(推薦)方法 3:使用 `retrying` 庫(舊版,已停止維護)方法 4:`requests` 自帶重試(適用于 HTTP 請求)方法 5:自定義裝飾器(靈活控制)方法…

2025年滲透測試面試題總結-滲透測試紅隊面試七(題目+回答)

網絡安全領域各種資源&#xff0c;學習文檔&#xff0c;以及工具分享、前沿信息分享、POC、EXP分享。不定期分享各種好玩的項目及好用的工具&#xff0c;歡迎關注。 目錄 滲透測試紅隊面試七 一百八十一、Shiro漏洞類型&#xff0c;721原理&#xff0c;721利用要注意什么&am…

Unity動畫系統使用整理 --- Playable

??Playable API?? 是一個強大的工具&#xff0c;用于更靈活地控制動畫、音頻、腳本等時間軸內容的播放和混合。它提供了比傳統 Animator 更底層、更可控的方式管理時間軸行為&#xff0c;尤其適合復雜動畫邏輯或動態內容組合的場景。 優點&#xff1a; 1.Playables API 支…

基于STM32、HAL庫的BMP390L氣壓傳感器 驅動程序設計

一、簡介: BMP390L 是 Bosch Sensortec 生產的一款高精度氣壓傳感器,專為需要精確測量氣壓和海拔高度的應用場景設計。BMP390L 具有更低的功耗、更高的精度和更快的響應速度。 二、硬件接口: BMP390L 引腳STM32L4XX 引腳說明VDD3.3V電源GNDGND地SCLPB6 (I2C1 SCL)I2C 時鐘線…

Arduino快速入門

Arduino快速入門指南 一、硬件準備 選擇開發板&#xff1a; 推薦使用 Arduino UNO&#xff08;兼容性強&#xff0c;適合初學者&#xff09;&#xff0c;其他常見型號包括NANO&#xff08;體積小&#xff09;、Mega&#xff08;接口更多&#xff09;。準備基礎元件&#xff1a…

破解 Qt QProcess 在 Release 模式下的“卡死”之謎

在使用 Qt 的 QProcess 以調用外部 ffmpeg/ffprobe 進行音視頻處理時&#xff0c;常見的工作流程是&#xff1a; gatherParams&#xff1a;通過 ffprobe 同步獲取媒體文件的參數&#xff08;分辨率、采樣率、聲道數、碼率等&#xff09;。 reencode&#xff1a;逐個文件調用 f…

MySQL 中 UPDATE 結合 SELECT 和 UPDATE CASE WHEN 的示例

概述 以下是 MySQL 中 UPDATE 結合 SELECT 和 UPDATE CASE WHEN 的示例&#xff1a; 一、UPDATE 結合 SELECT&#xff08;跨表更新&#xff09; 場景&#xff1a;根據 orders 表中的訂單總金額&#xff0c;更新 users 表中用戶的 total_spent 字段。 -- 創建測試表 CREATE T…

【MCP】魔搭社區MCP服務(高德地圖、everything文件搜索)

【MCP】魔搭社區MCP服務&#xff08;高德地圖、everything文件搜索&#xff09; 1、上手使用2、環境配置&#xff08;1&#xff09;cherry-studio配置&#xff08;2&#xff09;添加魔搭大模型服務&#xff08;如果已經設置了其他大模型服務&#xff0c;可跳過&#xff09;&…

MapReduce 的工作原理

MapReduce 是一種分布式計算框架&#xff0c;用于處理和生成大規模數據集。它將任務分為兩個主要階段&#xff1a;Map 階段和 Reduce 階段。開發人員可以使用存儲在 HDFS 中的數據&#xff0c;編寫 Hadoop 的 MapReduce 任務&#xff0c;從而實現并行處理1。 MapReduce 的工作…

MCU開啟浮點計算FPU

FPU 測試 1. FPU 簡介2. 協處理器控制寄存器&#xff08;CPACR&#xff09;3. 開啟FPU4. 驗證FPU&#xff08;Julia 分形實驗&#xff09; 1. FPU 簡介 FPU 即浮點運算單元&#xff08;Float Point Unit&#xff09;。浮點運算&#xff0c;對于定點 CPU&#xff08;沒有 FPU 的…

進程相關面試題20道

一、基礎概念與原理 1.進程的定義及其與程序的本質區別是什么&#xff1f; 答案&#xff1a;進程是操作系統分配資源的基本單位&#xff0c;是程序在數據集合上的一次動態執行過程。核心區別&#xff1a;? 動態性&#xff1a;程序是靜態文件&#xff0c;進程是動態執行實例…

React Hooks 精要:從入門到精通的進階之路

Hooks 是 React 16.8 引入的革命性特性,它讓函數組件擁有了類組件的能力。以下是 React Hooks 的詳細使用指南。 一、基礎 Hooks 1. useState - 狀態管理 import { useState } from react;function Counter() {const [count, setCount] = useState(0); // 初始值為0return …

springboot3+vue3融合項目實戰-大事件文章管理系統-更新用戶頭像

大致分為三步 首先在usercontroller里面加入方法 PatchMapping ("/updateAvatar")public Result upadateAvatar(RequestParam URL String avatarUrl){userService.updateAvater(avatarUrl);return Result.success();}url注解能驗證傳入的url是不是合法的&#xff0c…