编辑器Ueditor和SpringBoot 的整合方法

2025-05-29 0 89

1.先导入ueditor所有的包:在springboot static下

编辑器Ueditor和SpringBoot 的整合方法

2.导入需要的ueditor的js

编辑器Ueditor和SpringBoot 的整合方法

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

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 编辑器Ueditor和SpringBoot 的整合方法 https://www.kuaiidc.com/115471.html

相关文章

发表评论
暂无评论