spring boot 整合 ueditor 教程二:使用springmvc替换controller.jsp

2019-03-05 23:08|来源: 网路

接着上一篇文章,继续开始spring boot 整合 ueditor


下载ueditor1_4_3_3里有一个jsp的文件夹,那是官方提供的java 工具类,有一个lib目录、config.json和controller.jsp


lib目录是官方提供实力需要的jar包,我们已经使用maven替换,具体见:http://www.656463.com/springboot/bAVBNj.htm

config.json是ueditor的配置文件

controller.jsp是获取config.json中的配置


首先看看controller.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
	import="com.baidu.ueditor.ActionEnter"
    pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<%

    request.setCharacterEncoding( "utf-8" );
	response.setHeader("Content-Type" , "text/html");
	
	String rootPath = application.getRealPath( "/" );
	
	out.write( new ActionEnter( request, rootPath ).exec() );
	
%>


我们是整合spring boot,把jsp改为spring mvc的方式更舒服些

package h.y.n.web.controller;

import com.baidu.ueditor.ActionEnter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@Controller()
@RequestMapping("test/ueditor")
public class UEditorController {

    @RequestMapping(value = "/config")
    public void config(HttpServletRequest request, HttpServletResponse response) {
        response.setContentType("application/json");
        String rootPath = request.getSession().getServletContext().getRealPath("/");
        try {
            String exec = new ActionEnter(request, rootPath).exec();
            PrintWriter writer = response.getWriter();
            writer.write(exec);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


这个类都干了些啥,先到github把ueditor 的java源码下载下来,地址是:https://github.com/fex-team/ueditor/archive/v1.4.3.3.zip


把源码复制到你的项目中,当然你重新创建个项目更好。


未完待续......


相关问答

更多
  • 在hibernate的query 接口查询出一个list后 list里有两个方法 list.setFirstResult(int a); list.setMaxSize(int a); 第一个方法用来设置当前页要显示的第一条记录是从哪一个记录开始的 第二个方法用来设置每页的最大记录数 通过这个就足以实现分页了,先实现了功能再说吧,这样做反正是不太好呵呵
  • 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架。 spring-boot中使用mybatis持久层框架与原spring项目使用方式和注解都不相同,需要依赖mybatis-spring-boot包。 具体操作: 引入mybatis和数据库及其他项目依赖。 引入mybatis依赖。 引入mysql 驱动。 项目pom.xml一览。 这样完成spring boot整合mybitas配置oracle。
  • 你是说Mybatis的Mapper XML?这个要自己创建的,网上有很多开源工具可以自动创建
  • UTF-8 1.8 org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-thymeleaf org.springframework.boot spring-boot-starter-test test
  • spring
  • SpringBoot整合Mybatis http://blog.csdn.net/flight5630/article/details/51228916
  • 您必须在application.properties文件中为jsp文件定义前缀和后缀,如下所示: spring.mvc.view.prefix: /WEB-INF/jsp/ spring.mvc.view.suffix: .jsp You have to define the prefix and suffix for you jsp file in application.properties file like following: spring.mvc.view.prefix: /WEB-INF/j ...
  • 您的存储库未连接到控制器。 @Controller public class ManagementManufacturerController { @Autowired private ManufacturerService manufactureService; ---- 应该做的伎俩。 你已经用SessionFactory做了这个。 Autowired告诉Spring应该注入一个匹配类型和/或名称的Bean。 €:你的服务类没有实例化。 很难说为什么,但很可能你错过了一些@Component ...
  • 首先,Java EE和Spring是竞争性的框架。 一般来说,选择一个或另一个是最容易的,而不是试图混合它们。 从长远来看,它最终会减少初学者的混淆,减少互操作性方面的麻烦。 Java EE框架适用于Java EE容器(WildFly,TomEE,Payara等),而Spring框架适用于准系统servlet容器(Tomcat,Jetty等)。 JSF虽然是Java EE框架的一部分,但最初并不需要很多其他Java EE工件作为依赖关系,因此它可以毫不费力地在准系统servlet容器中运行。 只有JSTL被 ...