springboot thymeleaf ueditor 填坑

搞了两小时,累死哥哥了

我的项目结构是: springboot + maven + mybatis + thymeleaf  ...   呸呸呸,这些都不重要啦

下面开始正题

说说问题吧: 

刚开始我从官网下载的jsp版本的新鲜的ueditor,导入到自己的项目后发现上传图片那里说我配置文件没读到,神尴尬,我看了一下官方的文档,知道还要在服务端配置个控制器给他返回他自己的配置文件,(ps;我去,配置文件非要服务端返回,自己读取不就好了么,就像明明你可以自己吃饭,你把筷子给我让我喂你吃饭,没懂是个什么梗),好了,不吐槽了哈,虾米呐开始配置走起:

我没用官方提供的jar包  自己在maven 仓库找的dependency,把官方给的config.json放到了我的resource目录,结果访问config的时候是配置文件初始化失败,我晕,一看就知道他没访问到我的配置文件,这jar包好坑,于是我自己写吧..


先把文件拉在resource目录下面

springboot thymeleaf ueditor 填坑

springboot thymeleaf ueditor 填坑

配置一下服务端统一请求路径,请求到你即将要写的哪个控制器哦


springboot thymeleaf ueditor 填坑

springboot thymeleaf ueditor 填坑


然后是控制器:考虑你们都比较懒 我就直接粘代码给你们copy啦hhh...

@Controller  //打杂的控制器
public class CommonController {
    //ueditr后端配置
    @ResponseBody
    @RequestMapping(value = "ueditor.py",headers = "Accept=application/json")
    public String ueditor(@RequestParam("action") String action, @RequestParam("noCache") String nocache, HttpServletRequest request, HttpServletResponse response){
        try {
            response.setContentType("application/json;charset=utf-8");
            Resource resource = new ClassPathResource("config.json");
            File file = resource.getFile();
            BufferedReader br = new BufferedReader(new FileReader(file));
            StringBuilder stringBuilder = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null){
                stringBuilder.append(line);
            }
            return stringBuilder.toString();
        }catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }
}

然后把你的项目run起来,看你前端的图片是不是可以上传了。  至于上传那个java基础就可以ok的,就不讲了。主要还是填个坑...