springmvc+ueditor上传路径(个人备忘)

Posted freeatalk

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springmvc+ueditor上传路径(个人备忘)相关的知识,希望对你有一定的参考价值。

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(‘内容‘);
  ); 

 

以上是关于springmvc+ueditor上传路径(个人备忘)的主要内容,如果未能解决你的问题,请参考以下文章

springMVC -- 整合UEditor(富文本编辑器)

SpringMVC Ueditor1.4.3 未找到上传数据

UEditor使用总结(与SpringMVC整合)

UEditor for Java 配置(SpringMVC)

如何把ueditor中的多图上传功能

UMEditor(Ueditor mini)修改图片上传路径