SpringBoot中如何集成ThymeLeaf呢?
下文笔者将讲述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
即可输出以下效果
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


