SpringBoot整合模板引擎Thymeleaf 2022-06-14 01:37 178阅读 0赞 SpringBoot整合Thymeleaf是比较简单的。 \- 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> * 编写application.yml配置文件 spring: thymeleaf: cache: false mode: HTML5 其它的配置使用默认值即可。 \- 编写控制类 import java.util.Map; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/") public class ThymeleafController { @RequestMapping("/index") public String index(Map<String, Object> map){ map.put("user", "Tyrone"); return "index"; } } * 编写模板 [Thymeleaf菜鸟教程][Thymeleaf] <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8" /> <title>Insert title here</title> </head> <body> <p>Hello!<span th:text="${user}"></span>!<br />welcom to Thymeleaf's world</p> </body> </html> 注意:根据约定大于配置,springboot项目中的静态文件默认路径应该放在/resources/static, 模板文件路径:resources/templates.如下图: ![这里写图片描述][SouthEast] 最后创建启动类并运行 \- 浏览器测试 启动成功后,在浏览器中输入[http://localhost:8080/index][http_localhost_8080_index] 如图所示: ![这里写图片描述][SouthEast 1] 源代码链接:[https://github.com/myNameIssls/springboot-study][https_github.com_myNameIssls_springboot-study] 参考链接:[https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples][https_github.com_spring-projects_spring-boot_tree_master_spring-boot-samples] [Thymeleaf]: http://blog.csdn.net/mynameissls/article/details/72880647 [SouthEast]: /images/20220614/1390033fa68f4cf98377cd8e5f0ec098.png [http_localhost_8080_index]: http://localhost:8080/index [SouthEast 1]: /images/20220614/4f969663bc2d42c48ff1228d388f62f3.png [https_github.com_myNameIssls_springboot-study]: https://github.com/myNameIssls/springboot-study [https_github.com_spring-projects_spring-boot_tree_master_spring-boot-samples]: https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples
相关 Springboot整合thymeleaf模板 Thymeleaf是个XML/XHTML/HTML5模板引擎,可以用于Web与非Web应用。 Thymeleaf的主要目标在于提供一种可被浏览器正确显示的、格式良好的模板创建 - 日理万妓/ 2021年11月02日 04:54/ 0 赞/ 303 阅读
相关 springboot-模板引擎Thymeleaf 1 引入Thymeleaf <dependency> <groupId>org.springframework.boot</groupId> 朱雀/ 2022年04月17日 04:22/ 0 赞/ 213 阅读
相关 SpringBoot---Thymeleaf 模板引擎 > 一、使用Thymeleaf模板引擎开发 > > 1.在pom.xml文件中引入Thymeleaf依赖 > > <!--引入Thymeleaf 模板 雨点打透心脏的1/2处/ 2022年05月11日 14:14/ 0 赞/ 204 阅读
相关 SpringBoot——整合thymeleaf模板 SpringBoot常用模板引擎有 freemarker 和 thymeleaf,更推荐使用 thymeleaf。整合 thymeleaf 模板引擎很简单,只有两个步骤: 落日映苍穹つ/ 2022年05月24日 02:10/ 0 赞/ 189 阅读
相关 SpringBoot + Thymeleaf模板引擎 1、SpringBoot支持的常用的模板引擎有: Thymeleaf Freemarker 这里主要记录一下踩坑记录 2、创建一个springboot项 末蓝、/ 2022年05月27日 22:36/ 0 赞/ 133 阅读
相关 SpringBoot整合thymeleaf模板 首先在pom.xml文件中加入thymeleaf依赖 <dependency> <groupId>org.springframewor 迈不过友情╰/ 2022年06月14日 01:08/ 0 赞/ 188 阅读
相关 SpringBoot整合模板引擎Thymeleaf SpringBoot整合Thymeleaf是比较简单的。 \- 添加依赖 <dependency> <groupId>org.springfram 我会带着你远行/ 2022年06月14日 01:37/ 0 赞/ 179 阅读
相关 SpringBoot Thymeleaf 模板引擎 SpringBoot中提供了大量模板引擎,包括FreeMarker、Grooy、Thymeleaf、Velocity和Mustache,SpringBoot推荐使用Thymel Myth丶恋晨/ 2022年07月16日 12:11/ 0 赞/ 138 阅读
相关 SpringBoot——Thymeleaf模板引擎 Thymeleaf模板引擎 模板引擎 引入Thymeleaf 模板引擎使用 模板引擎 前端交给我们的页面,是html页面。如果是我们以前开发,我 谁借莪1个温暖的怀抱¢/ 2022年09月14日 02:28/ 0 赞/ 144 阅读
相关 SpringBoot整合模板引擎Thymeleaf SpringBoot整合模板引擎Thymeleaf 1,什么是Thymeleaf? Thymeleaf 是一个跟 Velocity、FreeMarker 类似的模板 港控/mmm°/ 2022年10月08日 00:43/ 0 赞/ 66 阅读
还没有评论,来说两句吧...