参考文档
thymeleaf 语法——th:text默认值、字符串连接、th:attr、th:href 传参、th:include传参、th:inline 内联、th:each循环、th:with、th:if_猎人在吃肉的博客-CSDN博客
代码演示
@Controller
public class TestController {
@Autowired
MenuService menuService;
@GetMapping(value = "/index")
public String index(Model model) {
List<Menu> list = menuService.list();
model.addAttribute("list", list);
model.addAttribute("name", "吕怡婷");
model.addAttribute("age", 22);
return "/layui/index";
}
@PostMapping(value = "/insert")
public String insert() {
return null;
}
@GetMapping(value = "/delete")
public String delete() {
return null;
}
}
@Controller
public class Test2Controller {
@Autowired
MenuService menuService;
@GetMapping(value = "/skip")
public String skip(Model model,String name,String age) {
model.addAttribute("age", age);
model.addAttribute("name", name);
return "/layui/skip";
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/lib/layui-v2.7.6/css/layui.css">
</head>
<body>
<link rel="stylesheet" href="/lib/layui-v2.7.6/layui.js">
<!--遍历-->
<div th:each="menu:${list}">
<span th:text="${menu.menuName}"></span>--<span th:text="${menu.id}"></span>
<br>
</div>
<!--测试text-->
<span th:text="${name}?'ok':'on'"></span>
<br>
<span th:text="${menu1}"></span>
<br>
变量:[[${name}]]
<br>
<!--字符串贫拼接-->
<span th:text="|${name}喜欢吃辣喜喜|"></span>
<br>
<!--跳转-->
<a th:href="@{/skip(name=${name},age=${age})}">跳转测试</a>
<!---->
<div th:with="name3=${name}+'xixix'">
<p th:text="${name3}">ha</p>
</div>
<p th:text="${name3}">jjj</p>
<h3> th:remove </h3>
<div >
all:<div th:remove="all"><div id="hello1">你好11</div></div>
body:<div th:remove="body"><div id="hello2">你好11</div></div>
tag:<div th:remove="tag"><div id="hello3">你好11</div></div>
tag:<div th:remove="none"><div id="hello4">你好11</div></div>
</div>
<th:block th:if="${age}==23">
<div>hahahaaaa</div>
<div>oooooo</div>
</th:block>
<!--<th:block th:replace="${name}" />-->
</body>
</html>
自学 使用thymeleaf提交form表单给controller(springboot)_thymeleaf提交表单_梦梦~~的博客-CSDN博客