<12>springboot集成thymeleaf模板引擎

  1. 创建一个springboot工程,导入以下依赖
<dependencies>
    <!--springboot框架web组件依赖-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <!--springboot集成tyhmeleaf模板引擎-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
  1. 可以配置关闭页面缓存,实现项目的热更新
# 设置thymeleaf模板引擎的前/后缀(可以选项),如下(默认会找resources/templates/xx.html)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html

# 关闭页面缓存,默认是true
spring.thymeleaf.cache=false

在这里插入图片描述
3. html页面引入thymeleaf调度器

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!--
xmlns:th="http://www.thymeleaf.org"引入thymeleaf模板引擎中央调度器
-->
<body>
<h1 th:text="${data}"></h1>
</body>
</html>
  1. IndexContrller测试类
@Controller
public class IndexController {
    @RequestMapping("/index")
    public String index(Model model) {
        model.addAttribute("data", "hello world");

        return "index";
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值