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