Java实现百度富文本编辑器UEditor
生活随笔
收集整理的這篇文章主要介紹了
Java实现百度富文本编辑器UEditor
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ?說起來?實現百度富文本編輯器也是比較簡單,主要就是?讀取?config.json
? ? ? ? 但是里面的坑也比較大? ?下面是我的步驟?以及我遇坑的過程
- 準備引入的jar包?這兩個包找不到的話?可以去官網、也可以加群Java交流群,在群文件自行下載:? QQ群:808249297
- 將靜態資源復制到資源下面
? ? ? ??
隨后重要的來了!?將config.json? 粘貼到?resources下面
? ? 這里如果不粘到這個下面?后面寫的controller會讀取不到? 會報錯
??
- 頁面上引入js
?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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL 标准发布第 15 部分:ISO/
- 下一篇: 关于vba word的一些用法