spring boot: 支持jsp,支持freemarker

spring boot: 支持jsp,支持freemarker

支持jsp:

加入依赖

<!--jsp-->
		<dependency>
			<groupId>org.apache.tomcat.embed</groupId>
			<artifactId>tomcat-embed-jasper</artifactId>
			<!--scope>provided</scope-->
		</dependency>
		<!--jsp-标签-->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-tomcat</artifactId>
		</dependency>

  

  

 

yml配置

spring:
      mvc:
         view:
            prefix: /WEB-INF/jsp/
            suffix: .jsp

  

 

webapp/WEB-FIN/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>

  

 

支持freemarket

依赖

<!--freemarka-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-freemarker</artifactId>
		</dependency>

  

 

yml配置

spring:
        freemarker:
    allow-request-override: false
    cache: false
    check-template-location: true
    charset: utf-8
    content-type: text/html
    expose-request-attributes: false
    expose-session-attributes: false
    expose-spring-macro-helpers: false
    suffix: .ftl
    template-loader-path: classpath:/templates

  

 

web.xml

可有可无

 

 

注册controller文件,

如果配置的是freemarker, 用@RestController ,模板输出就不能: return "模板"; 必须要 ModelAndView了

@RequestMapping("/test")
    public String test()
    {
        return "seller/list";
    }

  

改为:

@RequestMapping("/test")
    public ModelAndView test()
    {
        return new ModelAndView ("seller/list"); 

//如果不行,改为:
      return new ModelAndView ("seller/list.ftl");
}

  

 

否则就用@Controller注解

 

posted @ 2018-11-23 15:16  穆晟铭  阅读(719)  评论(0编辑  收藏  举报