Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一

Spring boot 视图解析与模板引擎

spring boot 默认不支持 jsp

需要引用第三方模板引擎技术实现页面渲染

第三方模板引擎 thymeleaf

thymeleaf 官方文档

www.thymeleaf.org/

第一使用 thymeleaf 先引入 依赖

org.springframework.boot

spring-boot-starter-thymeleaf

一般如果是高并发情况 不提议使用 thymeleaf

如果是单体项目 可以使用thymeleaf

页面默认存放位置 在 classpath:/templates/ 文件夹下

就是 resources 文件夹下的 templates

html 文件存放位置

Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一

通过控制器 来进行动态渲染 页面数据

Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一

模板引擎的数据渲染 基本写法
th:text=“Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一{xxx}” 表明渲染的是 是一个超链接
这种渲染 一般是去外部网站链接
列如 从你网站跳转到百度
th:href=“@{xxx}” 表明渲染的也是一个超联集
这种渲染 是 自己网站内部的跳转方式
列如从这个页面跳转到 另一个页面
$ 和 @ 是有区别的

Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一

给路径追加前缀

只需要在配置文件中加上

server.servlet.context-path=/json

Spring boot 如何使用视图解析器 thymeleaf 模板引擎来渲染页面 详解一

© 版权声明

相关文章

暂无评论

none
暂无评论...