版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/caox_90/article/details/85002737
环境
springboot1.5.8 、ueditor 1.4.3、thymeleaf
下载jsp版本ueditor
将ueditor后台源码拷贝到src/mian/java目录下,修改文件 ConfigManager
private void initEnv () throws FileNotFoundException, IOException { File file = new File( this.originalPath ); if ( !file.isAbsolute() ) { file = new File( file.getAbsolutePath() ); file = new File(file.getCanonicalPath()); } this.parentPath = file.getParent(); /** * 修改加载config文件路径 * */ ClassPathResource resource = new ClassPathResource(configFileName); file = resource.getFile(); BufferedReader br = new BufferedReader(new FileReader(file)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = br.readLine()) != null){ stringBuilder.append(line); } // String configContent = this.readFile( this.getConfigPath() );//原加载方式 String configContent = stringBuilder.toString(); try{ JSONObject jsonConfig = new JSONObject( configContent ); this.jsonConfig = jsonConfig; } catch ( Exception e ) { this.jsonConfig = null; } }
前端调用修改文件ueditor.config.js
var URL = rootPath + "js/ueditor/"; /** * 配置项主体。注意,此处所有涉及到路径的配置别遗漏URL变量。 */ window.UEDITOR_CONFIG = { //为编辑器实例添加一个路径,这个不能被注释 UEDITOR_HOME_URL: URL // 服务器统一请求接口路径 , serverUrl: rootPath + "/comm/ueditor"
将config.json拷贝到resouces文件夹下
在后台controller中增加对应的入口方法
//ueditr后端配置 @ResponseBody @RequestMapping(value = "/ueditor") public void ueditor(HttpServletRequest request, HttpServletResponse response) throws Exception { request.setCharacterEncoding( "utf-8" ); response.setHeader("Content-Type" , "text/html"); String realPath = request.getSession().getServletContext().getRealPath("/"); PrintWriter out = response.getWriter(); String exec = new ActionEnter(request, realPath).exec(); logger.info("ueditor后台配置"+exec); out.flush(); out.write(exec); }