1.先导入ueditor所有的包:在springboot static下
2.导入需要的ueditor的js
3.配置ueditor.config.js
的// 服务器统一请求接口路径://, serverurl:
(这个路径是个java类,和config.js的内容相同)
4.js里面执行1.var ue = ue.geteditor('editor');
函数
5.上传图片:
?
1
2
3
4
5
6
7
8
9
10
11
12
|
/* ueditor里面的上传图片 */
ue.editor.prototype._bkgetactionurl=ue.editor.prototype.getactionurl;
//action是config.json配置文件的action
ue.editor.prototype.getactionurl=function(action){
if (action == 'uploadimage'){
return [[@{/common/upload/image}]]; /* 这里填上你自己的上传图片的action */
} else if (action == 'uploadvideo' ){
return [[@{/common/upload/image}]];
} else {
return this ._bkgetactionurl.call( this , action);
}
};
|
6.上传图片的方法:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
@requestmapping (value = "/upload/image" , method = requestmethod.post, produces = mediatype.application_json_value)
@responsebody
public map<string,object> save(httpservletrequest req){
map<string,object> rs = new hashmap<string, object>();
multiparthttpservletrequest mreq = null ;
multipartfile file = null ;
string filename = "" ;
// 原始文件名 ueditor创建页面元素时的alt和title属性
string originalfilename = "" ;
try {
mreq = (multiparthttpservletrequest)req;
// 从config.json中取得上传文件的id
file = mreq.getfile( "upfile" );
if (!file.isempty()){
// 取得文件的原始文件名称
filename = file.getoriginalfilename();
originalfilename = filename;
string ext = (filenameutils.getextension(file.getoriginalfilename())).tolowercase();
string storepath = "" ;
if ( "jpg" .equals(ext) || "png" .equals(ext) || "jpeg" .equals(ext) || "bmp" .equals(ext)) {
storepath = "upload/image/" ;
} else {
storepath = "upload/video/" ;
}
//将图片和视频保存在本地服务器
string pathroot = req.getsession().getservletcontext().getrealpath( "" );
string path = pathroot + "/" + storepath;
file.transferto( new file(path+filename));
string domain = readproperties.getfiledomain();
string httpimgpath = domain + storepath + filename;
rs.put( "state" , "success" ); // ueditor的规则:不为success则显示state的内容
rs.put( "url" ,httpimgpath); //能访问到你现在图片的路径
rs.put( "title" , originalfilename);
rs.put( "original" , originalfilename);
}
} catch (exception e) {
e.printstacktrace();
rs.put( "state" , "文件上传失败!" ); //在此处写上错误提示信息,这样当错误的时候就会显示此信息
rs.put( "url" , "" );
rs.put( "title" , "" );
rs.put( "original" , "" );
}
return rs;
}
|
总结
以上所述是小编给大家介绍的编辑器ueditor和springboot 的整合方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对快网idc网站的支持!
原文链接:http://blog.csdn.net/cwl_0514/article/details/77451135
相关文章
猜你喜欢
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 49
-
2025-06-04 13
-
2025-05-25 25
-
2025-06-04 77
-
Armbian 系统 23.05 发布:基于 Debian 12,支持 i3 窗口管理器
2025-05-27 59
热门评论