springboot的优势之一:嵌入式servlet容器,缺点就是不支持JSP

如果要使用JSP模板,比如要引入外置servlet,需要以下几个步骤:

1)把pom.xml配置文件设置packing为

<packaging>war</packaging>

2)在pom.xml配置文件引入外置tomcat

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
        </dependency>

3)在application.yml设置spring.mvc.view的属性值,设置JSP对应的目录以及后缀

spring:
  mvc:
    view:
      prefix: /WEB-INF/jsp/
      suffix: .jsp
10-01 05:43