Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 亚洲免费黄色网,国产视频在线观看免费,日本一级淫片观看

          整合營(yíng)銷(xiāo)服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          Ueditor二次編輯word(doc和docx格式),SpringBoot后端

          ue+ueditor+springboot, 實(shí)現(xiàn)word文檔上傳編輯

          前言

          `前端導(dǎo)入word文檔(doc和docx格式都支持),Ueditor富文本回顯進(jìn)行二次編輯,目前ueditor項(xiàng)目archived了,實(shí)現(xiàn)兩種格式的相關(guān)材料相對(duì)稀缺。

          `解決思路:

          1.上傳word文件

          2.后臺(tái)讀取word內(nèi)容(圖片需要額外處理保存到服務(wù)器固定的地址,該地址能讓瀏覽器直接訪問(wèn)),生成html文件

          3.后臺(tái)讀取html文件內(nèi)容返回給前端


          一、目標(biāo)

          通過(guò)上傳word文件,通過(guò)后臺(tái)進(jìn)行解析回顯到前端。



          二、代碼步驟

          后端代碼結(jié)構(gòu):


          1.maven依賴庫(kù)

          <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi</artifactId>
          <version>3.15</version>
          </dependency>
          <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-ooxml</artifactId>
          <version>3.15</version>
          </dependency>
          <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-ooxml-schemas</artifactId>
          <version>3.15</version>
          </dependency>
          <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-scratchpad</artifactId>
          <version>3.15</version>
          </dependency>
          <dependency>
          <groupId>fr.opensagres.xdocreport</groupId>
          <artifactId>org.apache.poi.xwpf.converter.xhtml</artifactId>
          <version>1.0.6</version>
          </dependency>

          2.vue頁(yè)面讀取ueditor的配置

          代碼如下:

          /**
          * 獲取UE文件上傳配置
          * @param request
          * @param response
          * @throws IOException
          */
          @GetMapping(value = "/config")
          public void ueConfig(HttpServletRequest request, HttpServletResponse response) throws IOException {
          response.setContentType("application/json");
          response.setCharacterEncoding("utf-8");
          String urlPrefix = ueProperties.getSavepath();
          log.info("urlPrefix = "+urlPrefix);
          String exec = "{\n" +
          " /* 上傳圖片配置項(xiàng) */\n" +
          " \"imageActionName\": \"catcherImage\", /* 執(zhí)行上傳圖片的action名稱 */\n" +
          " \"imageFieldName\": \"upfile\", /* 提交的圖片表單名稱 */\n" +
          " \"imageMaxSize\": 2048, /* 上傳大小限制,單位B */\n" +
          " \"imageAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"], /* 上傳圖片格式顯示 */\n" +
          " \"imageCompressEnable\": true, /* 是否壓縮圖片,默認(rèn)是true */\n" +
          " \"imageCompressBorder\": 800, /* 圖片壓縮最長(zhǎng)邊限制 */\n" +
          " \"imageInsertAlign\": \"none\", /* 插入的圖片浮動(dòng)方式 */\n" +
          " \"imageUrlPrefix\": \"" + urlPrefix + "\", /* 圖片訪問(wèn)路徑前綴 */\n" +
          " \"imagePathFormat\": \"/ueditor/image/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " /* {filename} 會(huì)替換成原文件名,配置這項(xiàng)需要注意中文亂碼問(wèn)題 */\n" +
          " /* {rand:6} 會(huì)替換成隨機(jī)數(shù),后面的數(shù)字是隨機(jī)數(shù)的位數(shù) */\n" +
          " /* {time} 會(huì)替換成時(shí)間戳 */\n" +
          " /* {yyyy} 會(huì)替換成四位年份 */\n" +
          " /* {yy} 會(huì)替換成兩位年份 */\n" +
          " /* {mm} 會(huì)替換成兩位月份 */\n" +
          " /* {dd} 會(huì)替換成兩位日期 */\n" +
          " /* {hh} 會(huì)替換成兩位小時(shí) */\n" +
          " /* {ii} 會(huì)替換成兩位分鐘 */\n" +
          " /* {ss} 會(huì)替換成兩位秒 */\n" +
          " /* 非法字符 \\ : * ? \" < > | */\n" +
          " /* 具請(qǐng)?bào)w看線上文檔: fex.baidu.com/ueditor/#use-format_upload_filename */\n" +
          "\n" +
          " /* 涂鴉圖片上傳配置項(xiàng) */\n" +
          " \"scrawlActionName\": \"uploadscrawl\", /* 執(zhí)行上傳涂鴉的action名稱 */\n" +
          " \"scrawlFieldName\": \"upfile\", /* 提交的圖片表單名稱 */\n" +
          " \"scrawlPathFormat\": \"/ueditor/image/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " \"scrawlMaxSize\": 2048000, /* 上傳大小限制,單位B */\n" +
          " \"scrawlUrlPrefix\": \"\", /* 圖片訪問(wèn)路徑前綴 */\n" +
          " \"scrawlInsertAlign\": \"none\",\n" +
          "\n" +
          " /* 截圖工具上傳 */\n" +
          " \"snapscreenActionName\": \"uploadimage\", /* 執(zhí)行上傳截圖的action名稱 */\n" +
          " \"snapscreenPathFormat\": \"/ueditor/image/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " \"snapscreenUrlPrefix\": \"\", /* 圖片訪問(wèn)路徑前綴 */\n" +
          " \"snapscreenInsertAlign\": \"none\", /* 插入的圖片浮動(dòng)方式 */\n" +
          "\n" +
          " /* 抓取遠(yuǎn)程圖片配置 */\n" +
          " \"catcherLocalDomain\": [\"127.0.0.1\", \"localhost\", \"img.baidu.com\"],\n" +
          " \"catcherActionName\": \"catchimage\", /* 執(zhí)行抓取遠(yuǎn)程圖片的action名稱 */\n" +
          " \"catcherFieldName\": \"source\", /* 提交的圖片列表表單名稱 */\n" +
          " \"catcherPathFormat\": \"/ueditor/image/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " \"catcherUrlPrefix\": \"" + urlPrefix + "\", /* 圖片訪問(wèn)路徑前綴 */\n" +
          " \"catcherMaxSize\": 2048000, /* 上傳大小限制,單位B */\n" +
          " \"catcherAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"], /* 抓取圖片格式顯示 */\n" +
          "\n" +
          " /* 上傳視頻配置 */\n" +
          " \"videoActionName\": \"uploadvideo\", /* 執(zhí)行上傳視頻的action名稱 */\n" +
          " \"videoFieldName\": \"upfile\", /* 提交的視頻表單名稱 */\n" +
          " \"videoPathFormat\": \"/ueditor/video/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " \"videoUrlPrefix\": \"\", /* 視頻訪問(wèn)路徑前綴 */\n" +
          " \"videoMaxSize\": 10240000, /* 上傳大小限制,單位B,默認(rèn)10MB */\n" +
          " \"videoAllowFiles\": [\n" +
          " \".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\",\n" +
          " \".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\"], /* 上傳視頻格式顯示 */\n" +
          " /* 上傳文件配置 */\n" +
          " \"fileActionName\": \"uploadfile\", /* controller里,執(zhí)行上傳視頻的action名稱 */\n" +
          " \"fileFieldName\": \"upfile\", /* 提交的文件表單名稱 */\n" +
          " \"filePathFormat\": \"/ueditor/file/{yyyy}{mm}{dd}/\", /* 上傳保存路徑,可以自定義保存路徑和文件名格式 */\n" +
          " \"fileUrlPrefix\": \"\", /* 文件訪問(wèn)路徑前綴 */\n" +
          " \"fileMaxSize\": 10240000, /* 上傳大小限制,單位B,默認(rèn)10MB */\n" +
          " \"fileAllowFiles\": [\n" +
          " \".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\",\n" +
          " \".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\",\n" +
          " \".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\",\n" +
          " \".rar\", \".zip\", \".tar\", \".gz\", \".7z\", \".bz2\", \".cab\", \".iso\",\n" +
          " \".doc\", \".docx\", \".xls\", \".xlsx\", \".ppt\", \".pptx\", \".pdf\", \".txt\", \".md\", \".xml\"\n" +
          " ], /* 上傳文件格式顯示 */\n" +
          " /* 列出指定目錄下的圖片 */\n" +
          " \"imageManagerActionName\": \"listimage\", /* 執(zhí)行圖片管理的action名稱 */\n" +
          " \"imageManagerListPath\": \"/ueditor/image/{yyyy}{mm}{dd}/\", /* 指定要列出圖片的目錄 */\n" +
          " \"imageManagerListSize\": 20, /* 每次列出文件數(shù)量 */\n" +
          " \"imageManagerUrlPrefix\": \"" + urlPrefix + "\", /* 圖片訪問(wèn)路徑前綴 */\n" +
          " \"imageManagerInsertAlign\": \"none\", /* 插入的圖片浮動(dòng)方式 */\n" +
          " \"imageManagerAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"], /* 列出的文件類(lèi)型 */\n" +
          " /* 列出指定目錄下的文件 */\n" +
          " \"fileManagerActionName\": \"listfile\", /* 執(zhí)行文件管理的action名稱 */\n" +
          " \"fileManagerListPath\": \"/ueditor/file/{yyyy}{mm}{dd}/\", /* 指定要列出文件的目錄 */\n" +
          " \"fileManagerUrlPrefix\": \"\", /* 文件訪問(wèn)路徑前綴 */\n" +
          " \"fileManagerListSize\": 20, /* 每次列出文件數(shù)量 */\n" +
          " \"fileManagerAllowFiles\": [\n" +
          " \".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\",\n" +
          " \".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\",\n" +
          " \".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\",\n" +
          " \".rar\", \".zip\", \".tar\", \".gz\", \".7z\", \".bz2\", \".cab\", \".iso\",\n" +
          " \".doc\", \".docx\", \".xls\", \".xlsx\", \".ppt\", \".pptx\", \".pdf\", \".txt\", \".md\", \".xml\"\n" +
          " ] /* 列出的文件類(lèi)型 */\n" +
          "}";
          PrintWriter writer = response.getWriter();
          writer.write(exec);
          writer.flush();
          writer.close();
          }

          ```

          3.前端導(dǎo)入文件

          代碼如下:

          methods: {
          ready(editorInstance) {
            this.editorInstance=editorInstance
            async uploadWordFile(event) {
            const file = event.target.files[0];
            if (!file) return;
            // 將Word文件轉(zhuǎn)換為HTML
            const htmlContent = await this.convertWordToHtml(file);
            const jsonData = JSON.parse(htmlContent)
            // 設(shè)置UEditor的內(nèi)容
            console.log(jsonData)
            this.editorInstance.execCommand('inserthtml',jsonData.data)
          },
          async convertWordToHtml(wordFile) {
            // 這里應(yīng)該是Word文件轉(zhuǎn)HTML的后端接口調(diào)用代碼
            // 假設(shè)有一個(gè)轉(zhuǎn)換Word為HTML的后端API
            const formData = new FormData();
            formData.append('file', wordFile);
            const response = await fetch('/api/ue/uploadFile',{
            method:'POST',
            body:formData
          })
          if (response.ok) {
          	return await response.text();
          }
          throw new Error('轉(zhuǎn)換失敗');
          }
          }


          4.后端讀取文件生成html

          代碼如下:

          
          /** word文檔上傳
          *
          * @param file
          * @return
          */
          @PostMapping("/uploadFile")
          public Object uploadFile(@RequestParam(name = "file") MultipartFile file){
            String filename = file.getOriginalFilename();
            JSONObject result = new JSONObject();
            String visitHtml = "";
            try {
              if (filename.endsWith(".docx")) {
              //TODO 處理docx格式的
              visitHtml = WordConverHtmlUtils.docxToHtmlText(file, ueProperties);
              } else if (filename.endsWith(".doc")) {
              //TODO 處理doc格式的
              visitHtml = WordConverHtmlUtils.docToHtmlText(file, ueProperties);
            } else {
            	log.error("不支持的文件格式!");
            }
            result.put("state", "SUCCESS");
            result.put("data", visitHtml);
            log.info("result: {}", result.toString());
            } catch (Exception e) {
           		 log.error("文件找不到異常!");
            	 e.printStackTrace();
            }
            return result;
          }

          5.WordConverHtmlUtils工具類(lèi)

          ??????????

          options.URIResolver(new BasicURIResolver(picUri));

          picUri地址,必須能通過(guò)瀏覽器直接訪問(wèn),否則編輯器中無(wú)法渲染出來(lái)圖片; 比如作者:http://localhost:8000/resource/ueditor/file/20240404/1712220732312.png(本地搭建NG測(cè)試)

          ??????????

          代碼如下:
          package com.ue.demo.utils;
          import cn.hutool.core.lang.UUID;
          import com.ue.demo.config.UeProperties;
          import lombok.extern.slf4j.Slf4j;
          import org.apache.poi.hwpf.HWPFDocument;
          import org.apache.poi.hwpf.converter.PicturesManager;
          import org.apache.poi.hwpf.converter.WordToHtmlConverter;
          import org.apache.poi.hwpf.usermodel.PictureType;
          import org.apache.poi.xwpf.converter.core.BasicURIResolver;
          import org.apache.poi.xwpf.converter.core.FileImageExtractor;
          import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
          import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
          import org.apache.poi.xwpf.usermodel.XWPFDocument;
          import org.springframework.web.multipart.MultipartFile;
          import org.w3c.dom.Document;
          import javax.xml.parsers.DocumentBuilderFactory;
          import javax.xml.transform.OutputKeys;
          import javax.xml.transform.Transformer;
          import javax.xml.transform.TransformerFactory;
          import javax.xml.transform.dom.DOMSource;
          import javax.xml.transform.stream.StreamResult;
          import java.io.*;
          import java.nio.file.Files;
          import java.nio.file.Path;
          import java.nio.file.Paths;
          /**
          * @author:Peanut
          * @create: 2024-04-05 10:22
          * @version: 1.0.0
          * @description:
          */
          @Slf4j
            public class WordConverHtmlUtils {
                  private final static String FILE_URL_PRE = "/ueditor/file/";
                  /**
                  * 上傳docx文檔,返回解析后的Html
                  */
                  public static String docxToHtmlText(MultipartFile file, UeProperties ueProperties) throws Exception {
                  try {
                  String fileName = UUID.fastUUID().toString();
                  //圖片存放地址
                  String imagePath = ueProperties.getSavepath().concat(FILE_URL_PRE).concat("/");
                  String fileOutName = imagePath.concat(fileName).concat(".html");
                  log.info("上傳docx文檔解析");
                  log.info("上傳docx文檔,返回解析后的Html, imagePath:{}", imagePath);
                  log.info("fileOutName:{}", fileOutName);
                  //獲取一個(gè)用操作Word的對(duì)象
                  XWPFDocument document = new XWPFDocument(file.getInputStream());
                  //導(dǎo)出為html時(shí)的一些基本設(shè)置類(lèi)
                  XHTMLOptions options = null;
                  //判斷word文件中是否有圖片
                  if(document.getAllPictures().size() > 0) {
                  //獲取默認(rèn)的對(duì)象,設(shè)置縮進(jìn)indent
                  options = XHTMLOptions.getDefault().indent(4);
                  // 如果包含圖片的話,要設(shè)置圖片的導(dǎo)出位置
                  File imageFolder = new File(imagePath);
                  //設(shè)置圖片抽取器的目的地文件夾 用于存放圖片文件
                  options.setExtractor(new FileImageExtractor(imageFolder));
                  // URI resolver word的html中圖片的目錄路徑
                  //??????????????????????????????????
                  //?????????? 這里需要設(shè)置為前端能過(guò)直接訪問(wèn)到的圖片地址, 比如作者:http://localhost:8000/resource/ueditor/file/20240404/1712220732312.png,
                  //?????????? 否則,ueditor編輯器無(wú)法顯示word文檔中的圖片
                  String picUri = ueProperties.getShowpath().concat(imagePath.substring(imagePath.indexOf("ueditor")));
                  options.URIResolver(new BasicURIResolver(picUri));
                }
                //獲取輸出的html文件對(duì)象
                File outFile = new File(fileOutName);
                if(!outFile.getParentFile().exists()){
                outFile.getParentFile().mkdirs();
                }
                //創(chuàng)建所有的父路徑,如果不存在父目錄的話
                outFile.getParentFile().mkdirs();
                //創(chuàng)建一個(gè)輸出流
                OutputStream out = new FileOutputStream(outFile);
                //html轉(zhuǎn)換器
                XHTMLConverter.getInstance().convert(document, out, options);
                log.info("html轉(zhuǎn)換器 success");
                //處理生成的html,字符串形式給前端
                return readHtmlStr(fileOutName);
                } catch (Exception e) {
                log.error("docxToHtmlText 解析異常", e);
                }
                return "";
          }
          /**
          * 上傳doc格式Word文檔,返回解析后的Html
          * @param file
          * @param ueProperties
          * @return
          * @throws Exception
          */
          public static String docToHtmlText(MultipartFile file, UeProperties ueProperties) throws Exception {
                //使用字符數(shù)組流獲取解析的內(nèi)容
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                OutputStream outStream = new BufferedOutputStream(baos);
                try {
                String fileName = UUID.fastUUID().toString();
                //將上傳的文件傳入Document轉(zhuǎn)換
                //圖片存放地址
                String docPath = ueProperties.getSavepath().concat(FILE_URL_PRE).concat("/");
                String imagePath = docPath.concat("image/");
                String fileOutName = docPath.concat(fileName).concat(".html");
                log.info("上傳doc文檔,返回解析 ");
                log.info("fileOutName:{}", fileOutName);
                //創(chuàng)建圖片文件的存儲(chǔ)目錄
                new File(imagePath).mkdirs();
                //poi中doc文檔對(duì)應(yīng)的實(shí)體類(lèi)
                HWPFDocument hwpfDocument = new HWPFDocument(file.getInputStream());
                //使用空的文檔對(duì)象構(gòu)建一個(gè)轉(zhuǎn)換對(duì)象
                WordToHtmlConverter converter = new WordToHtmlConverter(DocumentBuilderFactory
                .newInstance()
                .newDocumentBuilder()
                .newDocument());
                //設(shè)置存儲(chǔ)圖片的管理者--使用匿名內(nèi)部類(lèi)實(shí)現(xiàn) 該類(lèi)實(shí)現(xiàn)了PicturesManager接口,實(shí)現(xiàn)了其中的savePicture方法
                converter.setPicturesManager(new PicturesManager() {
                FileOutputStream out = null;
                //在下面的processDocument方法內(nèi)部會(huì)調(diào)用該方法 用于存儲(chǔ)word中的圖片文件
                @Override
                public String savePicture(byte[] bytes, PictureType pictureType, String name, float width, float height) {
                try {
                //單個(gè)照片的保存
                out = new FileOutputStream(imagePath + name);
                out.write(bytes);
                } catch (IOException exception) {
                exception.printStackTrace();
                }finally {
                if(out != null) {
                try {
                out.close();
                } catch (IOException e) {
                e.printStackTrace();
                }
                }
          }
          //這里要返回給操作者(HtmlDocumentFacade)一個(gè)存儲(chǔ)的路徑 用于生成Html時(shí)定位到圖片資源
          //??????????????????????????????????
          //?????????? 這里需要設(shè)置為前端能過(guò)直接訪問(wèn)到的圖片地址, 比如作者:http://localhost:8000/resource/ueditor/file/20240404/1712220732312.png,
          //?????????? 否則,ueditor編輯器無(wú)法顯示word文檔中的圖片
          			return ueProperties.getShowpath().concat(imagePath.substring(imagePath.indexOf("ueditor"))).concat(name);
                }
                });
                //使用外觀模式,將hwpfDocument文檔對(duì)象設(shè)置給HtmlDocumentFacade中的Document屬性
                converter.processDocument(hwpfDocument);
                //獲取轉(zhuǎn)換器中的document文檔
                Document htmlDocument = converter.getDocument();
                //充當(dāng)文檔對(duì)象模型 (DOM) 樹(shù)形式的轉(zhuǎn)換源樹(shù)的持有者 -- 源樹(shù)
                DOMSource domSource = new DOMSource(htmlDocument);
                //轉(zhuǎn)換器 該對(duì)象用于將源樹(shù)轉(zhuǎn)換為結(jié)果樹(shù)
                Transformer transformer = TransformerFactory.newInstance().newTransformer();
                //設(shè)置輸出時(shí)的以什么方式輸出,也可說(shuō)是結(jié)果樹(shù)的文件類(lèi)型 可以是html/xml/text或者是一些擴(kuò)展前三者的擴(kuò)展類(lèi)型
                transformer.setOutputProperty(OutputKeys.METHOD , "html");
                //設(shè)置一些必要的屬性 設(shè)置輸出時(shí)候的編碼為utf-8
                transformer.setOutputProperty(OutputKeys.ENCODING , "utf-8");
                //轉(zhuǎn)換 將輸入的源樹(shù)轉(zhuǎn)換為結(jié)果樹(shù)并且輸出到streamResult中
                transformer.transform(domSource , new StreamResult(new File(fileOutName)));
                log.info("html轉(zhuǎn)換器 success");
                //處理生成的html,字符串形式給前端
                return readHtmlStr(fileOutName);
                } catch (Exception e) {
                log.error("docToHtmlText 異常", e);
                } finally {
                baos.close();
                outStream.close();
                }
                return null;
          }
          /**
          * 讀取html文件,轉(zhuǎn)成字符串返回給前端
          * 去除換行,以及連續(xù)兩個(gè)空格
          * @param htmlDirPath html文件路徑
          * @return
          * @throws IOException
          */
          private static String readHtmlStr(String htmlDirPath) throws IOException {
          log.info("處理生成的html,字符串形式給前端:{} ...Start..", htmlDirPath);
          String htmlStr = "";
          try {
          Path htmlPath = Paths.get(htmlDirPath);
          htmlStr = new String(Files.readAllBytes(htmlPath));
          htmlStr = htmlStr.replaceAll("\\n", "");
          htmlStr = htmlStr.replaceAll("\\s{2,}", " ");
          log.info("處理生成的html,字符串形式給前端。。。end");
          } catch (IOException e) {
          log.error("處理生成的html,字符串形式出錯(cuò)了, {}", e.getMessage());
          }
          return htmlStr;
          }
          }


          6.后端配置文件

          代碼如下:

          spring.application.name=ue
          server.port=8000
          ##UE編輯器配置
          #編輯器訪問(wèn)服務(wù)器的圖片地址
          ue.showpath=http://localhost:8000/resource
          #ue文件存儲(chǔ)路徑前綴
          ue.savepath=/Users/cookie/Documents/coding/uedemo
          ```
          !!! ue.showpath=生產(chǎn)上有nginx需要在nginx.conf進(jìn)行配置


          三、實(shí)現(xiàn)效果

          成功通過(guò)導(dǎo)入word文章,回顯內(nèi)容到ueditor編輯器


          總結(jié)

          *贈(zèng)人玫瑰,手留余香*

          源碼地址:

          https://gitee.com/gwancookie/uedemo

          **讀取word文檔生成html借鑒:**

          https://blog.csdn.net/qq_44717657/article/details/124497326

          文以C#及VB.NET后端程序代碼示例展示如何將HTML轉(zhuǎn)為XML文件。轉(zhuǎn)換時(shí),調(diào)用Word API -Free Spire.Doc for .NET 提供的文檔加載方法及文檔保存的方法來(lái)實(shí)現(xiàn)。轉(zhuǎn)換的代碼步驟很簡(jiǎn)單,具體可參考以下內(nèi)容。


          引入dll

          1.通過(guò)NuGet安裝dll(2種方法)

          1.1可以在Visual Studio中打開(kāi)“解決方案資源管理器”,鼠標(biāo)右鍵點(diǎn)擊“引用”,“管理NuGet包”,然后搜索“Free Spire.Doc”,點(diǎn)擊“安裝”。等待程序安裝完成。

          1.2將以下內(nèi)容復(fù)制到PM控制臺(tái)安裝:

          Install-Package FreeSpire.Doc -Version 10.2

          2.手動(dòng)添加dll引用

          可通過(guò)手動(dòng)下載包到本地,然后解壓,找到BIN文件夾下的Spire.Doc.dll。然后在Visual Studio中打開(kāi)“解決方案資源管理器”,鼠標(biāo)右鍵點(diǎn)擊“引用”,“添加引用”,將本地路徑BIN文件夾下的dll文件添加引用至程序。


          將HTML轉(zhuǎn)為XML

          轉(zhuǎn)換時(shí),可參考如下代碼來(lái)進(jìn)行:

          1. 創(chuàng)建Document類(lèi)的對(duì)象。
          2. 調(diào)用Document.LoadFromFile(string fileName, FileFormat fileFormat)方法加載HTML文檔。
          3. 通過(guò)Document.SaveToFile(string fileName, FileFormat fileFormat)方法保存為XML格式到指定路徑。

          C#

          using Spire.Doc;
          
          namespace HTMLtoXML
          {
              class Program
              {
                  static void Main(string[] args)
                  {
                      //創(chuàng)建Document類(lèi)的對(duì)象
                      Document doc = new Document();
          
                      //加載html文件
                      doc.LoadFromFile("sample.html",FileFormat.Html);
          
                      //保存為XML格式
                      doc.SaveToFile("HTMLtoXML.xml", FileFormat.Xml);
                      System.Diagnostics.Process.Start("HTMLtoXML.xml");
                  }
              }
          }

          vb.net

          Imports Spire.Doc
          
          Namespace HTMLtoXML
              Class Program
                  Private Shared Sub Main(args As String())
                      '創(chuàng)建Document類(lèi)的對(duì)象
                      Dim doc As New Document()
          
                      '加載html文件
                      doc.LoadFromFile("sample.html", FileFormat.Html)
          
                      '保存為XML格式
                      doc.SaveToFile("HTMLtoXML.xml", FileFormat.Xml)
                      System.Diagnostics.Process.Start("HTMLtoXML.xml")
                  End Sub
              End Class
          End Namespace

          轉(zhuǎn)換效果:

          —End—

          大家好,最近在工作中用到了一個(gè)不一樣接口文檔生成器,EasyYapi 接口生成器

          下面是來(lái)分享給大家如何操作,在idea 編輯器中很方便。

          鏈接:http://easyyapi.com/documents/index.html EasyYapi官方文檔.

          下載插件

          重啟IDEA,配置EasyYapi

          獲取token

          使用

          快捷鍵 Alt+insert

          Java注釋規(guī)范(配合EasyYapi使用)

          api demo
          
          /**
           * 分類(lèi)名稱
           * 分類(lèi)備注/描述
           *
           * @module 歸屬項(xiàng)目
           */
          @RestController
          @RequestMapping(value = "/pathOfCtrl")
          public class MockCtrl {
          
              /**
              * api名稱
              * api描述
              * @param param1 參數(shù)1的名稱或描述
              * @param param2 可以用`@link`來(lái)表示當(dāng)前參數(shù)的取值是某個(gè)枚舉{@link some.enum.or.constant.class}
              * @param param3 當(dāng)目標(biāo)枚舉字段與當(dāng)前字段名不一致,額外指定{@link some.enum.or.constant.class#property1}
              * @return 響應(yīng)描述
              */
              @RequestMapping(value = "/pathOfApi1")
              public Result methodName1(long param1,
                                @RequestParam String param2,
                                @RequestParam(required = false, defaultValue = "defaultValueOfParam3") String param3){
                  ...
              }
          
          
              /**
              * 默認(rèn)使用`application/x-www-form-urlencoded`,
              * 對(duì)于`@RequestBody`將使用`application/json`
              * 可以用注解`@Deprecated`來(lái)表示api廢棄
              * 也可以用注釋`@deprecated`
              *
              * @deprecated 改用{@link #methodName3(String)}
              */
              @Deprecated
              @RequestMapping(value = "/pathOfApi2")
              public Result methodName2(@RequestBody MockDtoOrVo jsonModel){
                  ...
              }
          
              /**
              * 所有注釋或者參數(shù)描述中都可以使用`@link`來(lái)引用另一個(gè)API
              * 例如:
              * 請(qǐng)先訪問(wèn){@link #methodName4(String)}
          
              * 也可以使用`@see`來(lái)引用另一個(gè)API
              *
              * @param param1 參數(shù)1的名稱或描述 可以從{@link #methodName5(String)}中獲得
              * @see #methodName6(String)
              * @deprecated 改用{@link #methodName7(String)}
              */
              @Deprecated
              @RequestMapping(value = "/pathOfApi3")
              public Result methodName3(long param1){
                  ...
              }
          
              ...
          }
          model(dto/vo) demo
          public class MockDtoOrVo {
          
              /**
               * 字段注釋
               */
              private Long field1;
          
              private Double field2;//注釋也可以寫(xiě)在這
          
              /**
               * 使用@see來(lái)說(shuō)明當(dāng)前字段的取值是某個(gè)枚舉
               * @see some.enum.or.constant.class
               */
              private int field3;
          
              /**
               * 當(dāng)目標(biāo)枚舉字段與當(dāng)前字段名不一致,額外指定
               * @see some.enum.or.constant.class#property1
               */
              private int field4;
          
              /**
               * 可以用注解`@Deprecated`來(lái)表示字段被廢棄
               * 也可以用注釋`@deprecated`
               * @deprecated It's a secret
               */
              @Deprecated
              private int field5;
          
              /**
               * 如果使用javax.validation的話
               * 可以使用@NotBlank/@NotNull表示字段必須
               */
              @NotBlank
              @NotNull
              private String field6;
          
              ...
          }
          

          可以登錄自己搭建yapi 服務(wù)上查看到

          感覺(jué)這種方式不用寫(xiě)swagger 還需要寫(xiě)配置,當(dāng)然,看個(gè)人和公司想法。

          借鑒:https://blog.csdn.net/qq_41604890/article/details/117299544


          主站蜘蛛池模板: 伊人色综合一区二区三区| 无码国产精品一区二区免费I6 | 久久精品国产第一区二区| 91秒拍国产福利一区| 精品国产日韩亚洲一区| 精品女同一区二区三区在线| 亚洲一区二区三区无码国产| 国产乱码一区二区三区爽爽爽| 无码AⅤ精品一区二区三区| 精品无码国产AV一区二区三区 | 91久久精品无码一区二区毛片 | 日本一区二区在线免费观看| 国产成人综合一区精品| 一本一道波多野结衣AV一区| 无码人妻久久久一区二区三区| 丝袜人妻一区二区三区| 国产天堂一区二区综合| 国产精品毛片a∨一区二区三区| 人妻无码一区二区视频| 久久无码人妻精品一区二区三区| 日本韩国黄色一区二区三区| 视频一区二区三区人妻系列| 国产91精品一区| 一区二区三区日本电影| 亚洲午夜日韩高清一区| 亚洲一区精品伊人久久伊人| 久久精品国产一区二区三区不卡| 一区二区三区内射美女毛片| 久久久不卡国产精品一区二区| 国产在线精品一区二区不卡麻豆| 久久AAAA片一区二区| 天堂资源中文最新版在线一区 | 消息称老熟妇乱视频一区二区| 亚洲日本va午夜中文字幕一区| 日本一区二区三区在线观看| 久久亚洲AV午夜福利精品一区| 麻豆一区二区在我观看| 无码视频免费一区二三区| 国产伦一区二区三区免费| 精品人体无码一区二区三区 | 国产成人片视频一区二区 |