springboot+Thymeleaf demo 每天进步百分之一

1.导入架包

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

2.配置Thymeleaf

    thymeleaf:
       cache: false
       prefix: classpath:/templates/
       suffix: .html
       encoding: UTF-8
       content-type: text/html
       mode: HTML5 

3.写个测试的controller

@Controller
public class ThymeleafTestController {


    @GetMapping("/hello")
    public String helloHtml(ModelMap map){
            map.put("hello","thyeleaf测试");
         return "/index";
     }


}

4.写个测试的页面


<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Hello World!title>
head>
<body>
    <h1 th:inline="text">Helloh1>
    <p th:text="${hello}">p>
body>
html>

注:测试页面的文件名必须与controller返回的一致
5运行项目查看测试页面数据
http://localhost:8080/hello
springboot+Thymeleaf demo 每天进步百分之一_第1张图片

你可能感兴趣的:(springboot)