首页 > 编程语言 > 详细

Spring Boot中使用 Thymeleaf

时间:2019-06-30 00:50:16      阅读:93      评论:0      收藏:0      [点我收藏+]

1.pom.xml引入thymeleaf

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2.关闭缓存application.properties

spring.thymeleaf.cache=false

3.编写Controller类

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
@RequestMapping("/home")
public class HomeController {

    @RequestMapping(value = "/index")
    public String index(Map<String,Object> map) {
        map.put("userName","Bill Gates");
        return "index";
    }
}

4.模板html

/resources/templates/index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"></meta>
    <title>Title</title>
</head>
<body>
<h1>hello,<span th:text="${userName}"></span></h1>
</body>
</html>

5.运行结果

访问地址:http://localhost:8090/home/index

hello,Bill Gates

Spring Boot中使用 Thymeleaf

原文:https://www.cnblogs.com/bqh10086/p/11108266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!