日韩精品欧美激情国产一区_中文无码精品一区二区三区在线_岛国毛片AV在线无码不卡_亞洲歐美日韓精品在線_使劲操好爽好粗视频在线播放_日韩一区欧美二区_八戒八戒网影院在线观看神马_亚洲怡红院在线色网_av无码不卡亚洲电影_国产麻豆媒体MDX

springboot集成ueditor富文本編輯器

時間:2020-07-08 23:11:34 類型:JAVA
字號:    
支持上傳到 本地、七牛云

  1. 文件導(dǎo)入

      新建springboot項(xiàng)目

      pom文件引入

    <dependency>
              <groupId>com.dcssn</groupId>
              <artifactId>ueditor-spring-boot-starter</artifactId>
              <version>2.0.1</version>
     </dependency>

      com.dcssnueditor-spring-boot-starter2.0.1

      下載百度編輯器最新版本1.4.3.3 Jsp UTF-8版本

      創(chuàng)建ueditor目錄 resources > static > ueditor ,將源碼拷貝到目錄中

      jsp目錄只保留 config.json 文件即可

      結(jié)構(gòu)如下圖

            

            1.png

項(xiàng)目配置

   application.yml文件

   ue:
     config-file: static/ueditor/jsp/config.json #resources目錄下配置文件的位置
     server-url: /ueditor.do #服務(wù)器統(tǒng)一請求接口路徑
     local: #上傳到本地配置
       url-prefix: /uploads/ #"/"結(jié)尾 自定義上傳時字段無意義
       physical-path: F:/java/uploads/ #存儲文件的絕對路徑 必須使用標(biāo)準(zhǔn)路徑"/"作為分隔符  自定義上傳時字段無意義
     qiniu: #上傳到七牛云配置 參數(shù)對應(yīng)官方文檔 https://developer.qiniu.com/kodo/sdk/1239/java
       accessKey: ---
       secretKey: ---
       cdn: https://--- #融合 CDN 加速域名
       bucket: ---
       zone: zone0


 static/ueditor/ueditor.config.js

  將serverUrl 改為application.yml 中server.servlet.context-path(如果你設(shè)置了此值則加上) + ue.server-url 的值

    2.png

  config.json

  注意:圖片訪問路徑前綴(imageUrlPrefix)、視頻訪問路徑前綴、文件訪問路徑前綴不要賦值,會影響回顯,其余參數(shù)可以按照百度文檔修改

  上傳文件大小

  spring上傳文件默認(rèn)最大1MB,上傳文件大小會先被spring限制,config.json文件大小限制要小于spring的設(shè)置,我們可以將spring的限制設(shè)大點(diǎn)

 spring:
    servlet:
      multipart:
        max-file-size: 500MB
        max-request-size: 500MB

測試:

  新建Controller 添加mapping

   @GetMapping("/")
   public String index() {
       return "ue";
   }

  在templates下新建頁面ue.html

   <!DOCTYPE html>
   <html xmlns:th="http://www.springframework.org/schema/jdbc">
   <head>
       <meta charset="UTF-8"/>
       <title>ueditor</title>
       <style>
           #editor {
               width: 1024px;
               height: 500px;
           }
       </style>
   </head>
   <body>
   <div id="editor" type="text/plain"></div>
   <script th:src="@{/ueditor/ueditor.config.js}"></script>
   <script th:src="@{/ueditor/ueditor.all.min.js}"></script>
   <script th:src="@{/ueditor/lang/zh-cn/zh-cn.js}"></script>
   <script>
       UE.getEditor('editor');
   </script>
   </body>
   </html>

  上傳到七牛云 要添加@EnableQiniuUploader注解

        如有問題可以加群:806893930 

自定義上傳

  1.當(dāng)前服務(wù)自定義處理

  實(shí)現(xiàn)com.baidu.ueditor.spring.EditorUploader接口,創(chuàng)建實(shí)現(xiàn)類的bean注入到spring容器中

  案例中有實(shí)現(xiàn)的例子,實(shí)現(xiàn)類是 com.example.ueditorspringbootstarterexample.MyEditorUploader

       2.直傳到遠(yuǎn)程服務(wù)器
            http://fex.baidu.com/ueditor/#qa-customurl

    <script>
        UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
        UE.Editor.prototype.getActionUrl = function(action) {
            if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
                return 'http://a.b.com/upload.php';
            } else if (action == 'uploadvideo') {
                return 'http://a.b.com/video.php';
            } else {
                return this._bkGetActionUrl.call(this, action);
            }
        }
        UE.getEditor('editor');
    </script>

    文章來自:https://github.com/weiangongsi/ueditor-spring-boot-starter-example

<