spring boot 學習筆記(二) 構建web支持jsp


一、必須將項目打包成war

<packaging>war</packaging>

 

 

二、pom.xml加入依賴包

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jsp支持-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<scope>compile</scope>
</dependency>

 

 

 

 

 

 

 

 

 

 

 

三、application.properties

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

spring.thymeleaf.cache=false    //這個是關閉thymeleaf緩存
spring.thymeleaf.enabled = false  //關閉thymeleaf模板

 

 

 

 

 

四、在項目中src/main/下建立 webapp/WEB-INF/jsps/

 

 

五、controller

@Controller
public class TestController {
  @RequestMapping("jsps")
public ModelAndView testJsp(){
return new ModelAndView("index");
}
}

 

 

 

 

 

 

六、訪問 http://localhost:8080/jsps ok。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM