spring boot整合ueditor上传图片

1、下载ueditor的jsp版本
链接:https://pan.baidu.com/s/11Y18nqlCFfdpTnq_I4twWw
提取码:36i7

在这里插入图片描述

2、新建项目
在这里插入图片描述

3、把ueditor里面的所有文件复制到项目的static下的新建的ueditor里
在这里插入图片描述

4、新建一个ServerController,注意一定要单独写一个Controller不要在其他Controller里面写,写以下内容

@Controller
public class ServerController {
  @RequestMapping(value = "/config")
  public void config(HttpServletRequest request, HttpServletResponse response) {
    response.setContentType("application/json");
    String rootPath = ClassUtils.getDefaultClassLoader().getResource("").getPath() + "static/ueditor/jsp";
    try {
      response.setCharacterEncoding("UTF-8");
      String exec = new ActionEnter(request, rootPath).exec();
      System.out.println(exec);
      PrintWriter writer = response.getWriter();
      //writer.write(new ActionEnter(request, rootPath).exec());//不能这样写,会重复上传图片,虽然图片一样,前后端得到的图片名称不一致
      writer.write(exec);
      writer.flush();
      writer.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

5、找到jsp文件夹下的config.json文件修改“imageUrlPrefix”(之前是空)
在这里插入图片描述

6、找到ueditor.config.js
在这里插入图片描述
找到代码:

var server_url=
window.location.protocol+"//"+window.location.hostname+":"+window.location.port

serverUrl: server_url+"/config"

两处修改后为:
在这里插入图片描述

7、之后便可以上传图片了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值