前后端不分离的方式

thymeleaf 静态资源配置:





thymeleaf配置
动静分离,前后端
配置thymeleaf
thymeleaf静态资源配置


SpringBoot整合thymeleaf模板引擎
步骤1:pom文件中引入它的依赖。

步骤2:application.properties配置thymeleaf相关配置。

扩展:th:,这个是thymeleaf的标签写法(这种方式适合做前后端分离的模式,这个文件如果直接拿到左面去展开,它不会加载这个thymeleaf标签的功能,也就是前端页面写好,后端人员只需要在th:text后编写即可)。

依赖:spring-boot-starter-thymeleaf
application.properties,静态资源配置
40%
如果要用spring-boot-starter-parent2.0之后的版本 spring.thymeleaf.content-type 改为 spring.thymeleaf.servlet.content-type=text/html
#thymeleaf 静态资源配置
spring.thymeleaf.prefix=classpath:/templates
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存 线上改为true
spring.thymeleaf.cache=false
thymeleaf控制器
适合动静分离
thymeleaf动态模板的相关配置:

thymeleaf 静态资源配置
2、 SpringBoot整合thymeleaf
①添加依赖:

②添加配置:

③在resources/templates下创建Thymeleaf静态页面(html格式文件)


④添加Controller,在Controller中可以通过ModeMap传递数据

ThymeleafController 类
Thymeleaf 模板引擎 页面 动态加载内容
thymeleaf 静态资源配置
thymeleaf 引入依赖
SpringBoot整合thymeleaf:
1.添加依赖:

2.添加配置:

3.编写Controller,可以通过ModelMap传递数据:

4.添加Thymeleaf静态页面,后缀就是html,可以通过th:text="${}"设置文本(会覆盖原来的文本),方便前后端分离:

5.注意:配置前缀时如果有多级文件夹,要用“.”分隔,类似这样
spring.thymeleaf.prefix=classpath:/templates.thymeleaf
thymeleaf 模板配置
thymeleaf模板引擎
thymeleaf配置
thymeleaf 配置
thymeleaf静态资源配置
thymeleaf config segment