Thymeleaf 官网:https://www.thymeleaf.org/
Thymeleaf 在Github 的主页:https://github.com/thymeleaf/thymeleaf
引入ThymeleafThymeleaf 语法学习org.springframework.boot spring-boot-starter-thymeleaf
我们做个最简单的练习 :我们需要查出一些数据,在页面中展示
1、修改测试请求,增加数据传输;
package com.zjb.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping("/test")
public String test(Model model){
model.addAttribute("msg","hello,SpringBoot");
return "test";
}
}
2、我们要使用thymeleaf,需要在html文件中导入命名空间的约束,方便提示。
我们可以去官方文档中看一下命名空间拿来过来:
xmlns:th="http://www.thymeleaf.org"
3、我们去编写下前端页面
Title
4、启动测试!
th:text 、th:utextpackage com.zjb.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TestController {
@RequestMapping("/test")
public String test(Model model){
model.addAttribute("msg","hello,SpringBoot");
return "test";
}
}
Title
th:each 遍历package com.zjb.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.Arrays;
@Controller
public class TestController {
@RequestMapping("/test")
public String test(Model model){
model.addAttribute("users", Arrays.asList("lisi","zhangsan"));
return "test";
}
}
Title
关于网站图标说明:
首先2.2.x 和 2.2.x之前的版本 配置方式是不一样:
2.2.x之前配置:
只需要在yml文件中配置
spring:
mvc:
favicon:
enabled: false
以及在resources文件夹中添加 favicon.ico 图片既可
2.2.x之后配置:
不需要在yml文件中配置, 而是在html中配置
nosoul
成功



