ueditor编辑器java使用_java/springboot整合UEditor编辑器
官网下载jsp版ueditor放进项目,其实放在哪个目录看项目习惯(有些按照网上的来就是路径问题导致),主要是获取配置的时候能找到相应的路径。
页面上引入相应js,加上也可script方式
ueditor加载会去读取:服务器统一请求接口路径,默认为:serverUrl: URL + "jsp/controller.jsp"
加载时首先会以get方式去读取配置信息(jsp/config.json里面的内容),然后再以post请求去上传图片或视频(请求后面带的参数会不一样【get】http://xxxx/xx?action=config或者【post】http://xxxx/xx?action=uploadimage)
get请求不到的话会报:请求后台配置项http错误,上传功能将不能正常使用!
get请求到了但返回配置错误的话上传会出错:
需要注意的是jsp版本的,而使用的是spring boot,请求应该经过控制器,而不能直接去访问这个jsp,当我们直接在浏览器输入这个请求http://xxxx/ueditor/jsp/controller.jsp?action=config&&noCache=12342时你会发现,这成了一个下载链接,可以下载contoller.jsp。
所以注意如果不修改serverUrl: URL + "jsp/controller.jsp"那一定要保证controller.jsp能正常访问且返回config.json里面的配置。
返回格式一定需要是这样:
在此提供两种方式获取config配置:
1.继续使用读取js/config.json目录里的配置,修改ueditor.config.js中配置的服务器统一请求接口路径serverUrl的值去后台执行方法获取,如下:
后台方法(方法名自定义):
这个rootPath是指向的是config.json所在的目录(static/js/plugins/ueditor/jsp),spring boot中应该这样修改才能获取的到,然后用PrintWriter来输出json格式的配置信息。那么这个方法就作为了ueditor向服务器发送请求的控制器了,从而取代了controller.jsp的作用
这个controller可以用现有的,也可新建。但一定要注意这个请求一定是http://xxxx/config不能是http://xxxx/file(或其他)/config,代码如下:
@Controller
public class Config {
@RequestMapping(value="/config")
public void config(HttpServletRequest request, HttpServletResponse response) {
response.setContentType("application/json");
String rootPath = ClassUtils.getDefaultClassLoader().getResource("").getPath()+"static/js/plugins/ueditor/jsp";
System.out.println(rootPath);
try {
String exec = new ActionEnter(request, rootPath).exec();
System.out.println(exec);
PrintWriter writer = response.getWriter();
writer.write(exec);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
而不应该是这样:
后台方法还有一层/file
如果确要如此,必须满足下面获取路径的条件。
因为跟踪请求方法看:
ActionEnter方法里面有一个request.getRequestURI():获取请求的地址链接(浏览器中输入的地址)与getConfigPath()【this.parentPath + File.separator + "config.json"】(会取上一层路径)
且继续执行会有:
结果:
rootPath:/target/classes/static/js/plugins/ueditor/jsp
uri:/config
originalPath:/target/classes/static/js/plugins/ueditor/jsp/config
getConfigPath方法就能正确获取到config.json地址:/target/classes/static/js/plugins/ueditor/jsp/config.json
而如果是 /file/config那获取到的路径:/target/classes/static/js/plugins/ueditor/jsp/file/config.json此路径就会错误。
用此方式相应的当选择了图片post提交时候先判断action
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
// 如果触发了下面三个动作中,则进行文件上传操作
if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage') {
return Tools.ctxPath + '/file/uploadimage';
} else {
return this._bkGetActionUrl.call(this, action);
}
}
以此来完成自定义路径上传(当然方法可统一一个,根据action来判断执行,如下)
2.不使用jsp/controller.jsp文件,直接从服务器处获取配置文件:
方法:
@RequestMapping("/uploadimage")
@ResponseBody
public Object uploadimage(@RequestParam(name = "action", required = false) String action,@RequestParam(name = "upfile", required = false) MultipartFile upfile, HttpServletRequest request) {
JSONObject object = new JSONObject();
if (action != null && action.equals("config")) {//获取配置文件
return JSONUtil.parse(UEditorUtil.UEDITOR_CONFIG);
} else if (action != null && action.equals("uploadimage")) {//直接自定义上传:oss
if (upfile != null) {
//{state:”数据状态信息”,url:”图片回显路径”,title:”文件title”,original:”文件名称”}
try {
return ossUtil.uploadimage(upfile);
} catch (Exception e) {
e.printStackTrace();
logger.error(e);
object.put("state", "err");
return object;
}
} else {
object.put("state", "文件为空");
return object;
}
} else {
object.put("state", "不支持该操作");
return object;
}
}
UEditorUtil帮助类:(把config.json里面的配置直接写成json字符串进行返回)
public class UEditorUtil {
public final static String UEDITOR_CONFIG = "{" +
"\"imageActionName\": \"uploadimage\"," +
"\"imageFieldName\": \"upfile\"," +
"\"imageMaxSize\": 2048000," +
"\"imageAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"]," +
"\"imageCompressEnable\": true," +
"\"imageCompressBorder\": 1600," +
"\"imageInsertAlign\": \"none\"," +
"\"imageUrlPrefix\": \"\"," +
"\"imagePathFormat\": \"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"" +
"\"scrawlActionName\": \"uploadscrawl\"," +
"\"scrawlFieldName\": \"upfile\"," +
"\"scrawlPathFormat\": \"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"\"scrawlMaxSize\": 2048000," +
"\"scrawlUrlPrefix\": \"\"," +
"\"scrawlInsertAlign\": \"none\"," +
"" +
"\"snapscreenActionName\": \"uploadimage\"," +
"\"snapscreenPathFormat\": \"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"\"snapscreenUrlPrefix\": \"\"," +
"\"snapscreenInsertAlign\": \"none\"," +
"" +
"\"catcherLocalDomain\": [\"127.0.0.1\", \"localhost\", \"img.baidu.com\"]," +
"\"catcherActionName\": \"catchimage\"," +
"\"catcherFieldName\": \"source\"," +
"\"catcherPathFormat\": \"/ueditor/jsp/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"\"catcherUrlPrefix\": \"\"," +
"\"catcherMaxSize\": 2048000," +
"\"catcherAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"]," +
"" +
"\"videoActionName\": \"uploadvideo\"," +
"\"videoFieldName\": \"upfile\"," +
"\"videoPathFormat\": \"/ueditor/jsp/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"\"videoUrlPrefix\": \"\"," +
"\"videoMaxSize\": 102400000," +
"\"videoAllowFiles\": [" +
"\".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\"," +
"\".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\"]," +
"" +
"\"fileActionName\": \"uploadfile\"," +
"\"fileFieldName\": \"upfile\"," +
"\"filePathFormat\": \"/ueditor/jsp/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}\"," +
"\"fileUrlPrefix\": \"\"," +
"\"fileMaxSize\": 51200000," +
"\"fileAllowFiles\": [" +
"\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"," +
"\".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\"," +
"\".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\"," +
"\".rar\", \".zip\", \".tar\", \".gz\", \".7z\", \".bz2\", \".cab\", \".iso\"," +
"\".doc\", \".docx\", \".xls\", \".xlsx\", \".ppt\", \".pptx\", \".pdf\", \".txt\", \".md\", \".xml\"" +
"]," +
"" +
"\"imageManagerActionName\": \"listimage\"," +
"\"imageManagerListPath\": \"/ueditor/jsp/upload/image/\"," +
"\"imageManagerListSize\": 20," +
"\"imageManagerUrlPrefix\": \"\"," +
"\"imageManagerInsertAlign\": \"none\"," +
"\"imageManagerAllowFiles\": [\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"]," +
"" +
"\"fileManagerActionName\": \"listfile\"," +
"\"fileManagerListPath\": \"/ueditor/jsp/upload/file/\"," +
"\"fileManagerUrlPrefix\": \"\"," +
"\"fileManagerListSize\": 20," +
"\"fileManagerAllowFiles\": [" +
"\".png\", \".jpg\", \".jpeg\", \".gif\", \".bmp\"," +
"\".flv\", \".swf\", \".mkv\", \".avi\", \".rm\", \".rmvb\", \".mpeg\", \".mpg\"," +
"\".ogg\", \".ogv\", \".mov\", \".wmv\", \".mp4\", \".webm\", \".mp3\", \".wav\", \".mid\"," +
"\".rar\", \".zip\", \".tar\", \".gz\", \".7z\", \".bz2\", \".cab\", \".iso\"," +
"\".doc\", \".docx\", \".xls\", \".xlsx\", \".ppt\", \".pptx\", \".pdf\", \".txt\", \".md\", \".xml\"" +
"] " +
"" +
"}";
/**
* Ueditor的返回状态类型
*/
public enum UeditorMsg {
SUCCESS("SUCCESS"), ERROR("上传失败");
private String v;
UeditorMsg(String v) {
this.v = v;
}
public String get() {
return this.v;
}
}
}
注意上传成功后的返回格式:
JSONObject object=new JSONObject();
object.put("url", "");//这个url是前台回显路径(回显路径为config.json中的imageUrlPrefix+此处的url)
object.put("state", "SUCCESS");
object.put("original", "");
object.put("title", "");
最后具体怎样引入依赖项-百度
ueditor编辑器java使用_java/springboot整合UEditor编辑器相关推荐
- 很详细的SpringBoot整合UEditor教程
很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- springboot整合ueditor上传图片配置(JSP)从新建项目开始
第一步: 一.去ue官网下载他的源码(已经有的了就略过) 二.Eclipse新建项目ueditorDemo 项目目录如下: application.properties配置如下: 第二步: 一.解压下 ...
- 【Java进阶】SpringBoot整合Redis
SpringBoot整合Redis SpringBoot 操作数据:spring-data jpa jdbc mongodb redis SpringData 也是和 SpringBoot 齐名的项目 ...
- Java学习之SpringBoot整合SSM Demo
背景:在Java Web中Spring家族有着很重要的地位,之前JAVA开发需要做很多的配置,一堆的配置文件和部署调试一直是JavaWeb开发中的一大诟病,但现在Spring推出了SpringBoot ...
- ueditor上传图片回调_springboot+mybatis+oss整合ueditor
今天项目的管理后台需要用到编辑器,之前有用到一款编辑器,叫做wangEditor,这款编辑器虽然接入是很快,给我的感觉就是傻白甜,但是他的编辑器的功能是比较少,后面又将编辑器改成了百度的ueditor ...
- java路由分发_Java Springboot 整合RabbitMQ(四):路由(Routing)-B2B2C小程序电子商务...
在本文中,我们将实现另一个功能 -- 只订阅一部分消息.例如,我们只需要把严重的错误日志信息写入日志文件(存储到磁盘),但同时仍然把所有的日志信息输出到控制台中 绑定(Binding) 在之前的例子中 ...
- ueditor 图片上传 java_Spring+Vue整合UEditor富文本实现图片附件上传的方法
下载UEditor 下载完整源码和JSP版本 Spring后端集成 1. 解压完整源码,拷贝jsp目录下的java源码,到spring mvc后端 jsp目录下java源码 集成spring mvc后 ...
- springboot 整合文本编辑器(图片上传)
Ueditor 文件上传配置: ueditor.config.js serverUrl:填写自己的路径 jsp->config.json: imageActionName:填写自己写的文件上传的 ...
- java定时任务_java:springBoot使用@Scheduled注解配置定时任务
定时任务的实现有多种,其中一种就是使用Spring提供的注解: @Schedule . 下面举个简单的例子 1.先在springboot的入口处添加@EnableScheduling这个注解 2.总开 ...
最新文章
- oracle union详解,Oracle中的union和join
- 67道 Python自动化面试题
- 信息系统项目管理师-计算题专题(一)进度类计算
- swiper高度自适应_小程序自定义导航自适应高度
- 使用python 下载_使用python下载大量文件
- 第一百二十六期:代码以外的生存之道,献给每位入了坑的码农
- 屏幕中间显示已停用缩放_有关标签打印软件缩放工具的介绍
- jenkins修改数据存放路径
- springboot 使用spring的线程池异步执行
- Linux_shell 学习
- tcpserver检测断开qt_QTcpServer或QTcpClient(在服务器端)知道,已连接的客户端现已断开连接...
- 更改ESXi主机root用户密码
- 深圳瑞光康泰RBP-9000C血压仪对接
- Atitit.Hibernate中Criteria 使用总结and 关联查询 and 按照子对象查询 o9o
- Kepware欧姆龙驱动连接选型大全
- 联想启动Kind City项目:交互式全球合作鼓励同理心,共创建立于善意之上的未来
- 改变指标改变图(FusionChart)
- 九度笔记之 1364:v字仇杀队
- Carson带你学Android:你要的WebView与 JS 交互方式都在这里了
- YOLOV1-目标检测综述