日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java实现百度富文本编辑器UEditor

發布時間:2023/12/14 java 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java实现百度富文本编辑器UEditor 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ?說起來?實現百度富文本編輯器也是比較簡單,主要就是?讀取?config.json

? ? ? ? 但是里面的坑也比較大? ?下面是我的步驟?以及我遇坑的過程

  • 準備引入的jar包?這兩個包找不到的話?可以去官網、也可以加群Java交流群,在群文件自行下載:? QQ群:808249297
<!--用于ueditor--><dependency><groupId>com.cns.diy-ueditor</groupId><artifactId>json</artifactId><version>1.0</version></dependency><!--用于ueditor--><dependency><groupId>com.cns.diy-ueditor</groupId><artifactId>ueditor</artifactId><version>1.1.2</version></dependency>
  • 將靜態資源復制到資源下面

? ? ? ??

隨后重要的來了!?將config.json? 粘貼到?resources下面

? ? 這里如果不粘到這個下面?后面寫的controller會讀取不到? 會報錯

??

  • 頁面上引入js
<script th:src="@{/ueditor/ueditor.config.js}"></script> <script th:src="@{/ueditor/ueditor.all.js}"></script>

?html里面

<textarea style="width: 100%;height: 280px;" type="text" id="learnContent" name="learnContent" ></textarea>

js里面

var ue = UE.getEditor('learnContent', {zIndex: "0",toolbars: [['fullscreen', 'undo', 'redo', '|','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|','rowspacingtop', 'rowspacingbottom', 'lineheight', '|','customstyle', 'paragraph', 'fontfamily', 'fontsize', '|','directionalityltr', 'directionalityrtl', 'indent', '|','justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|','link', 'unlink', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|','simpleupload', 'insertimage', 'attachment','map', '|','horizontal', 'spechars', '|','inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol','deletecol', 'mergecells', 'mergeright','mergedown', 'splittocells', 'splittorows', 'splittocols', '|', 'preview', 'searchreplace']]});UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;UE.Editor.prototype.getActionUrl = function (action) {if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadvideo') {return '/upload/uploadUEditorImage?pid=' + '[[${id}]]';} else if (action == 'uploadfile') {return '/upload/uploadUEditorFile?pid=' + '[[${id}]]';} else {return this._bkGetActionUrl.call(this, action);}}

要注意的是? 要注意的是?要注意的是

?

?這里一定要打空格? 否則?報錯!!!

下面兩個是?視頻?或者圖片?文件的上傳接口? 可以把文件跟圖片寫在一個接口里面?后臺拿到去判斷該走那個方法就行了

?

?controller里面寫

@Controller @RequestMapping("/ueditor") public class UeditorController { @RequestMapping("/getJsonController") @ResponseBody public void getConfigInfo(HttpServletRequest request, HttpServletResponse response) { org.springframework.core.io.Resource res = new ClassPathResource("config.json"); InputStream is = null; response.setHeader("Content-Type", "text/html"); try { is = new FileInputStream(res.getFile()); StringBuffer sb = new StringBuffer(); byte[] b = new byte[1024]; int length = 0; while (-1 != (length = is.read(b))) { sb.append(new String(b, 0, length, "utf-8")); } String result = sb.toString().replaceAll("/\\*(.|[\\r\\n])*?\\*/", ""); JSONObject json = JSON.parseObject(result); PrintWriter out = response.getWriter(); out.print(json.toString()); } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } } }

在這里面修改?成controller的路徑?

?現在就大功告成了

? ?

? ? java前沿技術交流群:808249297

總結

以上是生活随笔為你收集整理的Java实现百度富文本编辑器UEditor的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。