先吐槽一下UEditor作為一個前端的js類庫,非要把4種后端的代碼給出來,而實際生產中用的框架不同,其代碼並不具有適應性。(通常類似其它項目僅僅是給出數據交互的規范、格式,后端實現就可以自由定制)
接下來還是說各種問題把
1.首先下載其jsp的版本...
然而我並沒有用jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" import="com.baidu.ueditor.ActionEnter" pageEncoding="UTF-8"%> <%@ page trimDirectiveWhitespaces="true" %> <% request.setCharacterEncoding( "utf-8" ); response.setHeader("Content-Type" , "text/html"); String rootPath = application.getRealPath( "/" ); out.write( new ActionEnter( request, rootPath ).exec() ); %>
改成springmvc的controller版本
@ResponseBody public String config(HttpServletRequest request){ String rootPath=request.getServletContext().getRealPath("/"); return new ActionEnter( request, rootPath+"static\\javascript\\plugins\\UEditor\\" ).exec(); }
對應項目config.json存放位置
2.記得要把給的lib下的包導入
3.項目加載上傳顯示找不到上傳數據
好!想都不用想,lib下ueditor-1.1.2.jar包妥妥的寫死了 妥妥的沖突了
查看源碼可知是通過request.getInputStream讀取的,而controller中request.getInputStream並不能讀取
經過大量debug模式斷點調試和查看springboot文檔
springboot會默認加載一個HiddenHttpMethodFilter,其request.getParameter方法會讀取流,導致之后讀取不了
在配置類中手動配置一個HiddenHttpMethodFilter的bean
@Bean public HiddenHttpMethodFilter hiddenHttpMethodFilter() { return new OrderedHiddenHttpMethodFilter(){ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { filterChain.doFilter(request, response); } }; }
發現一般的表單數據可以獲取到有內容的inputStream,而文件依舊不行
於是乎,繼續debug Orz
springboot還有個默認加載的MultipartResolver實現類為StandardServletMultipartResolver,會對request進行一個包裝(見上圖),request.getParts方法也是會讀取inputStream
網上找到的解決方法中重寫了ueditor-1.1.2.jar的BinaryUploader類,原因講的不清,實現感覺也不是很好(並沒讀配置),准備自己寫一個,未完待續