gpt4 book ai didi

编辑器Ueditor和SpringBoot 的整合方法

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 24 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章编辑器Ueditor和SpringBoot 的整合方法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

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 的整合方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对我网站的支持! 。

原文链接:http://blog.csdn.net/cwl_0514/article/details/77451135 。

最后此篇关于编辑器Ueditor和SpringBoot 的整合方法的文章就讲到这里了,如果你想了解更多关于编辑器Ueditor和SpringBoot 的整合方法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com