一.前期准备工作
后台代码以及配置
1. UEditor官方文档:
http://fex.baidu.com/ueditor/#server-deploy
2.官方下载源码包:http://ueditor.baidu.com/website/download.html#ueditor
3.下载源码包,解压
根据目录…\ueditor-1.4.3.3\jsp\src\com\baidu\ueditor将ueditor文件复制到java项目的src下,如果是idea放在 src\main\java\com下
4.在解压的源码包里根据…\ueditor-1.4.3.3\jsp找到config.json文件并且将该文件复制到src/main/resource下
5.导入相关的jar包
在pom.xml:
<!--富文本编辑器-->
<!--json包-->
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<!--commons-io包-->
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<!--commons-fileupload-->
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<!--commons-codec-->
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.13</version>
</dependency>
6.修改ConfigManager.java文件,把 this.originalPath 修改为src/main/resources/config.json,IDEA直接修改为 config.json即可。然后注释掉
if ( contextPath.length() > 0 ) {
this.originalPath = this.rootPath + uri.substring( contextPath.length() );
} else {
this.originalPath = this.rootPath + uri;
}
见图:
7.新建 controller
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
@Controller
public class UeditorController {
private static final Log log = LogFactory.getLog(UeditorController.class);
@RequestMapping("/config")
public void config(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, JSONException {
response.setContentType("application/json");
String rootPath = request.getSession().getServletContext().getRealPath("/");
try {
ActionEnter actionEnter = new ActionEnter(request, rootPath);
String exec=actionEnter.exec();
PrintW