SpringBoot中集成jsp展示


  • SpringBoot框架默認推薦的模板為: Thymeleaf 類似於Freemarker     .html  模板
    • Thymeleaf  freemarker  模板語法   index.html  ===>  歡迎: ${name} ===> 緩存 頁面靜態化
  • SpringBoot 與 jsp 集成
    • 引入依賴 jsp、jstl
<!-- 引入jstl標簽,配套jsp使用,可以不導入 -->
<dependency>
  <groupId>jstl</groupId>
  <artifactId>jstl</artifactId>
  <version>1.2</version>
</dependency>


<!-- 配置內嵌的tomcat解析jsp -->
<dependency>
  <groupId>org.apache.tomcat.embed</groupId>
  <artifactId>tomcat-embed-jasper</artifactId>
</dependency>
    • 在application.yml文件中配置試圖解析前綴和后綴,spring.mvc.view.prefix, spring.mvc.view.suffix
spring: profiles: # Activate test configuration active: dev mvc: view: # Configure prefix prefix: / # Configure suffix suffix: .jsp
    • 測試通過跳轉,新建UserController文件
@Controller @RequestMapping("user") public class UserController { @RequestMapping("findAll") public String findAll() { System.out.println("findAll"); return "index"; } }
    • 比如這里,可以通過  http://localhost:8989/zq/user/findAll 訪問可以打印出findAll,然后跳轉index.jsp
      • 如果處理完上述操作,仍不支持jsp運行 (新版本似乎不用配置這個)Edit Configuration --> Working directory --> $MODULE_DIR$ 


免責聲明!

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



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