SpringBoot中如何集成ThymeLeaf呢?

java-教程王 SpringBoot 发布时间:2022-01-08 16:33:05 阅读数:4589 1
下文笔者将讲述SpringBoot集成ThymeLeaf的方法,如下所示:
实现思路:
    1.在pom.xml中引入ThymeLeaf的相关依赖
	2.在Templates文件夹下编写相应的模板文件
例:
1.pom.xml  添加ThymeLeaf依赖
  <!-- ThymeLeaf 依赖 -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
  </dependency>

2.编写模板
<!DOCTYPE html>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>java265.com ThymeLeaf模板</title>
</head>
<body>
    This is ThymeLeaf file
<br />
<p  th:text="${msg}"></p>
</body>
</html>

3.编写Controller
@Controller
public class TestController {
    @RequestMapping("/index")
    public String test(Model m)
    {
         m.addAttribute("msg","adeal love java.");
         return "ThymeLeaf/index";
    }
}
-----运行springboot即可访问
http://localhost:8080/index 
即可输出以下效果
springBoot集成ThymeLeaf的示例分享
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/JavaFramework/SpringBoot/202201/2222.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者