1.先修改ueditor.config.js下的serverUrl,改成serverUrl: URL + "jsp/config"
2.Ueidtor会向服务器请求config.json,因为我配置的是jsp/config,所以路径是/plugins/UEditor/jsp/config?action=config
3.新建一个controller,@RequestMapping("/plugins/UEditor/jsp") ,新建一个方法@RequestMapping("/config"),两个加起来的路径是/plugins/UEditor/jsp/config
4.方法里头接受参数action,如果"config".equals(action),则response.sendRedirect(request.getContextPath()+"/plugins/UEditor/jsp/config.json");
5.上传图片和视频action分别是uploadimage和uploadvideo,这两个值可以在config.json查到,分别是imageActionName和videoActionName,controller代码:
@Controller @RequestMapping("/plugins/UEditor/jsp") public class UeditorController { @RequestMapping("/config") public void config(String action,HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException { if ("config".equals(action)) { System.err.println("config"); response.sendRedirect(request.getContextPath()+"/plugins/UEditor/jsp/config.json"); }else if("uploadimage".equals(action)) { System.err.println("uploadimage 转发到上传路径"); request.getRequestDispatcher("/fileUploadfile").forward(request, response); }else if ("uploadvideo".equals(action)) { System.err.println("uploadvideo 转发到上传路径"); request.getRequestDispatcher("/fileUploadfile").forward(request, response); } } }
6.上传完成之后返回的格式
Map<String, Object> map = new HashMap<String, Object>(); map.put("state", "SUCCESS");
//因为手机端用到,所以图片路径包含端口,并使用断点下载 map.put("url",req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+req.getContextPath()+ "/downloadfile?id="+fileid); map.put("title", "demo.jpg"); map.put("original", "demo.jpg"); return map ;
备注:获取文本内容UE.getEditor('editor').getContent()
回填文本内容:
var ue = UE.getEditor('editor'); ue.ready(function() { ue.setContent('内容'); });