Spring Boot 整合 Thymeleaf 模板引擎(一) 之 搭建 2022-04-10 14:22 102阅读 0赞 * **Thymeleaf是一个适用于Web和独立环境的现代服务器端Java模板引擎,能够处理HTML,XML,JavaScript,CSS甚至纯文本。** * **Spring Boot 官方推荐使用 Thymeleaf 而不是 JSP。** * **[Thymeleaf使用文档。][Thymeleaf]** # ** 1.Maven依赖包** # <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- thymeleaf依赖包 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> # **2.application.yml配置** # #thymeleaf模板配置 spring: thymeleaf: prefix: classpath:/templates/ suffix: .html cache: false #热部署文件,false页面不产生缓存,及时更新,true开启缓存 说明:其他属性采用[默认配置][Link 1] # 3.新建Controller # import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class IndexController { @RequestMapping("/") public String InitProject(Model model){ model.addAttribute("msg", "这是thymeleaf的测试"); return "index"; } } # **4.新建index.html放到templates目录下 ** # <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Thymeleaf</title> </head> <body> <h1 th:text="${msg}">哈哈哈</h1> </body> </html> # **5.启动项目如下:** # # ![watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA5NTc2NDU_size_16_color_FFFFFF_t_70][] # 其他可参考《[Thymeleaf 模板引擎简介 与 Spring Boot 整合入门][Thymeleaf _ _ Spring Boot]》 [Thymeleaf]: https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html [Link 1]: https://github.com/spring-projects/spring-boot/blob/v2.1.1.RELEASE/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/thymeleaf/ThymeleafProperties.java [watermark_type_ZmFuZ3poZW5naGVpdGk_shadow_10_text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTA5NTc2NDU_size_16_color_FFFFFF_t_70]: /images/20220328/14278db3f048450cabee05ff4aac6ca6.png [Thymeleaf _ _ Spring Boot]: https://blog.csdn.net/wangmx1993328/article/details/81054474
相关 Spring Boot Thymeleaf 模板引擎的使用 Spring Boot 中可以支持很多模板引擎,`Thymeleaf` 是 Spring Boot 官方推荐使用的模板引擎,虽然在社区 `Thymeleaf` 的性能被许多人所 £神魔★判官ぃ/ 2021年11月01日 09:56/ 0 赞/ 252 阅读
相关 Spring Boot 整合thymeleaf 模板引擎 Thymeleaf模板引擎是一个和Velocity、FreeMarker类似的模板引擎,它支持xml/xhtml/html5,且提供额外的模块与Spring MVC集成, 布满荆棘的人生/ 2022年01月06日 10:37/ 0 赞/ 147 阅读
相关 Spring Boot 整合 Thymeleaf 模板引擎(四) 之 表达式语法 注:这里只列举常用的表达式语法,更多其他详细参详thymeleaf官方文档[https://www.thymeleaf.org/doc/tutorials/3.0/thymel 本是古典 何须时尚/ 2022年03月16日 08:20/ 0 赞/ 122 阅读
相关 Spring Boot 整合 Thymeleaf 模板引擎(二) 之 外部属性文件 1.application.yml配置 thymeleaf模板配置 spring: thymeleaf: prefix 深碍√TFBOYSˉ_/ 2022年03月17日 04:20/ 0 赞/ 226 阅读
相关 Spring Boot 整合 Thymeleaf 模板引擎(三) 之 实现国际化 1.application.yml配置 thymeleaf模板配置 spring: thymeleaf: prefix: 小鱼儿/ 2022年03月17日 04:40/ 0 赞/ 72 阅读
相关 spring boot整合thymeleaf模板 spring boot整合thymeleaf模板 首先需要引入依赖 博主用的是gradle管理jar包, ![在这里插入图片描述][201901072205063 落日映苍穹つ/ 2022年03月29日 04:15/ 0 赞/ 96 阅读
相关 Spring Boot 整合 Thymeleaf 模板引擎(一) 之 搭建 Thymeleaf是一个适用于Web和独立环境的现代服务器端Java模板引擎,能够处理HTML,XML,JavaScript,CSS甚至纯文本。 Spring £神魔★判官ぃ/ 2022年04月10日 14:22/ 0 赞/ 103 阅读
相关 Spring Boot集成Thymeleaf模板引擎 一、Thymeleaf 模板介绍 Spring Boot 推荐使用Thymeleaf 来代替传统开发中的JSP,那么什么是Thymeleaf 模板引擎呢?下面就来简单的介 不念不忘少年蓝@/ 2022年05月27日 23:19/ 0 赞/ 105 阅读
相关 SpringBoot整合模板引擎Thymeleaf SpringBoot整合Thymeleaf是比较简单的。 \- 添加依赖 <dependency> <groupId>org.springfram 我会带着你远行/ 2022年06月14日 01:37/ 0 赞/ 182 阅读
相关 Spring Boot模板引擎(Thymeleaf) 背景 在前后端分离架构大行其道的当下,为什么Thymeleaf还未被淘汰,它到底有什么不可替代的优势? 1、易被对搜索引擎友好,它由服务端渲染,将页面直接输出到浏览器中 短命女/ 2022年09月09日 06:14/ 0 赞/ 74 阅读
还没有评论,来说两句吧...