第一步将jsp请求改成后台action处理,路径根据实际路径修改下;
第二步修改com.baidu.ueditor.ConfigManager中readFile方法(打包jar后原方法无法读取文件,不修改会出现开发时正常,打包后无法上传文件,详情请参考https://blog.csdn.net/antony1776/article/details/89249509)
/**
* 百度富文本配置(路径修改成实际路径)
* file_upload_path为文件上传路径,例如:E:/upload
*/
@RequestMapping(value = "/js/H-ui.admin_v3.0/lib/ueditor/1.4.3/jsp/controller.jsp")
public void ueditor_config() {
response.setHeader("Content-type", "text/html;charset=UTF-8");
response.setContentType("text/html;charset=utf-8");
try {
String rootPath = ResourceUtils.getURL("classpath:").getPath();
String exec = new ActionEnter(request, rootPath + "/static/").exec(file_upload_path);
PrintWriter writer = response.getWriter();
writer.write(exec);
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//修改ConfigManager
private String readFile(String path) throws IOException {
StringBuilder builder = new StringBuilder();
try {
//springboot打包jar后,无法读取文件,使用new BufferedReader(new //InputStreamReader(this.getClass()
// .getClassLoader()
// .getResourceAsStream()
// InputStreamReader reader = new InputStreamReader(new FileInputStream(path), "UTF-8");
// BufferedReader bfReader = new BufferedReader(reader);
BufferedReader bfReader = new BufferedReader(new InputStreamReader(this.getClass()
.getClassLoader()
.getResourceAsStream("static/js/H-ui.admin_v3.0/lib/ueditor/1.4.3/jsp/config.json")));
String tmpContent = null;
while ((tmpContent = bfReader.readLine()) != null) {
builder.append(tmpContent);
}
bfReader.close();
} catch (UnsupportedEncodingException e) {
// 忽略
}
return this.filter(builder.toString());
}
项目路径如下: