springboot 梳理3--简单整合模板引擎thymeleaf

1. pom.xml

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

 

 

2. yml

spring:

  thymeleaf:
    prefix: classpath:/templates/
    check-template-location: true
    suffix: .html
    encoding: utf-8
    servlet:
      content-type: text/html
    mode: HTML5
    cache: false

 

3.Controller层 LoginController

@Controller
public class LoginController {
    @GetMapping("/login")
    public String toLogin(Model model){
        model.addAttribute("name","sunrui");
        return "login";
    }
}

 

 

4. login.html

 

 

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<p th:text=" 'hello,' + ${name} + '!' "/>
</body>
</html>

 

posted @ 2021-01-29 14:56  Master_Sun  阅读(56)  评论(0编辑  收藏  举报