新版SpringBoot2.x的starter和常见模板引擎讲解

简介:介绍常用的SpringBoot2.x模板引擎和官方推荐案例
  1.SpringBoot2.X常⽤start介绍
     starter主要是简化依赖用的
            spring-boot-starter-web->⾥⾯包含多种依赖
    查看 pom⽂件 spring-boot-starter-parent-> spring-boot-dependencies ⾥⾯综合的很多依赖包
 
  2.模板引擎介绍
     JSP(后端渲染,消耗性能)
          Java Server Pages 动态网页技术,由应用服务器中的JSP引擎来编译和执行,再将生成的整个页面返回给客户端,可以写java代码,表达式语言(el、jstl),内建函数
          JSP->Servlet(占⽤JVM内存)permSize
           javaweb官⽅推荐
          springboot官⽅不推荐
     Freemarker
         FreeMarker Template Language(FTL) ⽂件⼀般保存为 xxx.ftl,严格依赖MVC模式,不依赖Servlet容器(不占⽤JVM内存),内建函数
    Thymeleaf (主推)
         轻量级的模板引擎(复杂逻辑业务的不推荐,解析DOM或者XML会占⽤多的内存)
         可以直接在浏览器中打开且正确显示模板页面
         直接是html结尾,直接编辑xdlcass.net/user/userinfo.html
  3.在pom.xml中添加Thymeleaf相应依赖
<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

  4.thymeleaf基础配置

#开发时关闭缓存,不然没法看到实时⻚⾯
 spring.thymeleaf.cache=false
 spring.thymeleaf.mode=HTML5
 #前缀
 spring.thymeleaf.prefix=classpath:/templates/
 #编码
 spring.thymeleaf.encoding=UTF-8
 #类型
 spring.thymeleaf.content-type=text/html
 #名称的后缀
 spring.thymeleaf.suffix=.html

 

 

posted @ 2021-06-30 16:04  Allen-LuoYi  阅读(101)  评论(0)    收藏  举报