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

springboot 梳理3--简单整合模板引擎thymeleaf(待修改)

 

 

<!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>

 

上一篇:SpringSecurity简单使用


下一篇:快速上手thymeleaf