- 1 依赖
- 2 application.yml
- 3 实体类
- 4 controller
- 5.$符号使用
- 6.*符号的使用
- 7.@符号的使用
- 8.#符号的使用
- 9.集合的遍历
- 10.thymeleaf如何定义变量
- 11.字面量
- 12.字符串拼接方式
- 13.比较运算符
- 14.逻辑运算符
- 15.三目运算符
- 16.分支结构,th:if,th:unless,th:switch,th:case
- 17.thymeleaf的一些常用的内置对象
- 18.内联
2 application.ymlorg.springframework.boot spring-boot-starter-thymeleaf
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?characterEncoding=utf-8
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
thymeleaf:
cache: false #开启模板缓存默认true
check-template: true
check-template-location: true
servlet:
content-type: text/html
enabled: true
encoding: UTF-8
excluded-view-names:
mode: HTML
prefix: classpath:/templates/
suffix: .html
mvc:
static-path-pattern: /static/**
web:
resources:
static-locations: classpath:/static
3 实体类
public class User {
private int id;
private String name;
private int age;
public User() {
}
public User(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
4 controller
@Controller
public class HelloController {
@GetMapping("/hello")
public String hello(Model model, HttpSession session) {
session.setAttribute("name","javavue");
List list = new ArrayList<>();
for (int i = 0 ; i < 5; i++) {
User user = new User();
user.setId(i);
user.setName("xiaolan"+i);
user.setAge(18);
list.add(user);
}
model.addAttribute("users",list);
User user = new User();
user.setId(11);
user.setAge(18);
user.setName("小白");
model.addAttribute("user",user);
return "hello";
}
}
5.$符号使用
$符号主要是取对象中的数据
6.*符号的使用
*符号也可以取对象中的数据
7.@符号的使用
@符号主要是用于引入文件
8.#符号的使用
#符号主要是根据当前浏览器的语言去相对应的国际化配置文件中取值
9.集合的遍历
11.字面量
12.字符串拼接方式
13.比较运算符
14.逻辑运算符
15.三目运算符
16.分支结构,th:if,th:unless,th:switch,th:case
| 偶数 基数 |
18.内联
hello [[${user.name}]]
hello [(${user.name})]
a better language'">
[[${str}]]
[(${str})]



