1. 程式人生 > >SpringBoot整合JSP

SpringBoot整合JSP

view depend -- art tomcat pen size spring cat

pom文件引入以下依賴

      <parent>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-parent</artifactId>

            <version>2.0.0.RELEASE</version>

      </parent>

      <dependencies>

            <!--
SpringBoot 核心組件 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <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> </dependencies>

在application.properties創建以下配置

spring.mvc.view.prefix=/WEB-INF/jsp/

spring.mvc.view.suffix=.jsp

後臺代碼

@Controller

publicclass IndexController {

      @RequestMapping("/index")

      public String index() {

            return"index";

      }

}

註意:創建SpringBoot整合JSP,一定要為war類型,否則會找不到頁面.

SpringBoot整合JSP