Spring Boot+SpringMVC使用ueditor(jsp版)
来源:互联网 发布:fbreader源码画线功能 编辑:程序博客网 时间:2024/05/16 14:00
最近遇到了在Spring Boot框架下使用ueditor的情况,由于以前只在ssm框架下使用过,所以记录一下配置过程。
此方式需要下载ueditor的源码。
1、把源码中 com.baidu.ueditor 包下的内容全部复制到项目中,然后把前台静态文件复制到webapp/ueditor目录下,然后把config.json也复制到此目录下,文件结构如下图。
2、创建一个自定义的Controller,代码如下:
package cn.bhmc.ueditor.controller;import java.io.IOException; import java.io.PrintWriter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.json.JSONException;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import com.baidu.ueditor.ActionEnter; @Controller @RequestMapping("/ueditor") public class UEditorController { @RequestMapping(value = "/config") public void config(HttpServletRequest request, HttpServletResponse response) { response.setContentType("application/json"); String rootPath = request.getSession().getServletContext() .getRealPath("/"); try { String exec = new ActionEnter(request, rootPath).exec(); PrintWriter writer = response.getWriter(); writer.write(exec); writer.flush(); writer.close(); } catch (IOException | JSONException e) { e.printStackTrace(); } } @RequestMapping("/main") public String main(){ return "base/main/main"; }}
3、修改ueditor.config.js文件中的serverUrl属性,改为 URL + “config”,拦截ueditor的请求到自定义的Controller中。
4、修改config.json中的imageUrlPrefix属性,改为你的项目地址,如:http://localhost:8080/bhmc ,imagePathFormat属性也可以修改,改成自定义的目录,要注意的是,如果imagePathFormat的前面有/的话,imageUrlPrefix的最后就不用加上/了,会重复。
5、最后,需要修改BinaryUploader中的上传源码,把save方法里的源码改为:
try { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile(conf.get("fieldName").toString()); String savePath = (String) conf.get("savePath"); String originFileName = multipartFile.getOriginalFilename(); String suffix = FileType.getSuffixByFilename(originFileName); originFileName = originFileName.substring(0,originFileName.length() - suffix.length()); savePath = savePath + suffix; long maxSize = ((Long) conf.get("maxSize")).longValue(); if (!validType(suffix, (String[]) conf.get("allowFiles"))) { return new BaseState(false, AppInfo.NOT_ALLOW_FILE_TYPE); } /***********/ //自定义 savePath = PathFormat.parse(savePath, originFileName); String [] savePathBySplit_temp = savePath.split("/"); String temp = ""; String fileName = savePathBySplit_temp[savePathBySplit_temp.length-1]; for(int i = 1;i < savePathBySplit_temp.length-1; i++){ if(i!=savePathBySplit_temp.length-2){ temp+=savePathBySplit_temp[i]+"/"; }else{ temp+=savePathBySplit_temp[i]; } } String pathTemp = request.getSession().getServletContext().getRealPath(temp); System.out.println(pathTemp+","+fileName); System.out.println(new File(pathTemp).exists()); File targetFile = new File(pathTemp); if(!targetFile.exists()){ targetFile.mkdirs(); } System.out.println(new File(pathTemp).exists()); /************/ //State storageState = StorageManager.saveFileByInputStream(multipartFile.getInputStream(),savePath, maxSize); State storageState = StorageManager.saveFileByInputStream(multipartFile.getInputStream(),pathTemp+"/"+fileName, maxSize); if (storageState.isSuccess()) { storageState.putInfo("url", PathFormat.format(savePath)); storageState.putInfo("type", suffix); storageState.putInfo("original", originFileName + suffix); } return storageState; }catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } return new BaseState(false, AppInfo.IO_ERROR);
然后,启动,创建一个编辑框,上传测试:
完成。
阅读全文
1 0
- Spring Boot+SpringMVC使用ueditor(jsp版)
- spring boot 、springMVC环境集成百度ueditor富文本编辑器,使用七牛云存储图片
- spring boot 、springMVC环境集成百度ueditor富文本编辑器,使用七牛云存储图片
- Spring-Boot使用jsp
- UEditor踩坑记(SpringMVC+Shiro+URLREWriter+JSP)
- spring Boot + Ueditor整合
- ueditor的使用jsp版
- UEditor具体使用(jsp)
- Spring boot(11) 使用jsp
- 13. Spring Boot 使用JSP
- SpringMVC 使用百度Ueditor
- JSP使用UEditor
- Jsp使用ueditor编辑器
- ueditor--JSP使用
- spring-boot入门(二)使用JSP视图
- Spring mvc UEditor jsp版本
- (11) spring boot使用jsp实例
- spring boot 使用jsp 的一些问题
- c++模板参数自动推导
- Jfinal(一)--------入门HelloWorld
- html5地理位置定位
- Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: forbidden (403)"原因
- js 实现页面的复制功能 clipboard.js
- Spring Boot+SpringMVC使用ueditor(jsp版)
- java 回文数
- EffectiveC++学习笔记-条款12
- STM32程序下载成功但是不运行
- Apache+PHP 解决上传文件大小限制的问题
- 如何查看devices已经发送的uevent事件
- ubuntu mysql root 远程访问
- JVM调优经验
- 数据应用达人之SQL基础教程分享6-比较与逻辑操作