源无极

导航

 

 

一、SpringBoot Starter讲解

   简单说springboot Starter 就是jar包的集合,集合了很多的依赖
    简介:介绍什么是SpringBoot Starter和主要作用

    1、官网地址:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#using-boot-starter
    
    2、starter主要简化依赖用的
        spring-boot-starter-web    ->里面包含多种依赖

    3、几个常用的starter
        spring-boot-starter-activemq
        spring-boot-starter-aop
        spring-boot-starter-data-redis
        spring-boot-starter-freemarker
        spring-boot-starter-thymeleaf
        spring-boot-starter-webflux

 

二 、SpringBoot2.x常见模板引擎讲解和官方推荐使用


    简介:介绍常用的SpringBoot2.x模板引擎和官方推荐案例

        1、JSP(后端渲染,消耗性能: 一般前后端不分析的小项目用到)
            Java Server Pages 动态网页技术,由应用服务器中的JSP引擎来编译和执行,再将生成的整个页面返回给客户端
            可以写java代码
            持表达式语言(el、jstl)
            内建函数
            JSP->Servlet(占用JVM内存)permSize
            javaweb官方推荐
            springboot不推荐 https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-jsp-limitations

        2、Freemarker 
            FreeMarker Template Language(FTL)  文件一般保存为 xxx.ftl
            严格依赖MVC模式,不依赖Servlet容器(不占用JVM内存)
            内建函数

        3、Thymeleaf (sprngboot主推)
            轻量级的模板引擎(负责逻辑业务的不推荐,解析DOM或者XML会占用多的内存)
            可以直接在浏览器中打开且正确显示模板页面

            直接是html结尾,直接编辑
            xdlcass.net/user/userinfo.html 

             这个路径的好处是可以伪装,此时它不一定是html页面
          

三、SpringBoot2.x整合模板引擎freemarker实战


    简介:SpringBoot2.x整合模板引擎freemarker实战

    1、Freemarker相关maven依赖
        

1 <!-- 引入freemarker模板引擎的依赖 -->
2         <dependency>
3             <groupId>org.springframework.boot</groupId>
4             <artifactId>spring-boot-starter-freemarker</artifactId>
5         </dependency>
6 
7      

 

    2、Freemarker基础配置(application.properties配置)
        

 1   # 是否开启thymeleaf缓存,本地为false,生产建议为true
 2         spring.freemarker.cache=false
 3 
 4         spring.freemarker.charset=UTF-8
 5         spring.freemarker.allow-request-override=false
 6         spring.freemarker.check-template-location=true
 7         #类型
 8         spring.freemarker.content-type=text/html
 9 
10         spring.freemarker.expose-request-attributes=true
11         spring.freemarker.expose-session-attributes=true
12         #文件后缀
13         spring.freemarker.suffix=.ftl
14         #路径
15         spring.freemarker.template-loader-path=classpath:/templates/

 


        

    3、建立文件夹
        1)src/main/resources/templates/fm/user/
        2)建立一个index.ftl


     

 

    4、简单测试代码编写和访问

5.ServerSettings类

6. application.properties配置

7.启动访问

 

4、SpringBoot2.x整合模板引擎thymeleaf实战(重点)

    官网地址:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html
    1、thymeleaf相关maven依赖
         

1             <dependency>
2                    <groupId>org.springframework.boot</groupId>
3                    <artifactId>spring-boot-starter-thymeleaf</artifactId>
4             </dependency>

 

    2、thymeleaf基础配置

    

  
 1         #开发时关闭缓存,不然没法看到实时页面
 2         spring.thymeleaf.cache=false
 3         spring.thymeleaf.mode=HTML5
 4         #前缀
 5         spring.thymeleaf.prefix=classpath:/templates/
 6         #编码
 7         spring.thymeleaf.encoding=UTF-8
 8         #类型
 9         spring.thymeleaf.content-type=text/html
10         #名称的后缀
11         spring.thymeleaf.suffix=.html

 

    3、建立文件夹
        1)src/main/resources/templates/tl/
        2)建立一个index.html

    4、简单测试代码编写和访问
        注意:$表达式只能写在th标签内部

1)

补充:将templates变成默认的可直接访问

2)同理和freemarker一样

3)

4)通过接口访问(开发中推荐使用)

5)


 thymeleaf  :     快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html

补充thymeleaf 简单 的使用

posted on 2018-11-29 22:13  源无极  阅读(192)  评论(0编辑  收藏  举报