if语句
条件判断使用th:if,它会判断表达式是否成立,表达式的结果支持boolean、number、character、String及其他类型。
满足下面情况下,if语句成立:
(1) 表达式的结果是数字且不是0
(2) 表达式的结果是字符串且不是false、off、no、0
(3) 表达式的结果是其他数据类型
switch case语句
(1) 类似Java的switch case语句:th:switch、th:case
(2) 使用th:case="*"来表示默认值
(3) 如果第一个th:case结果为true,则其它所有的th:case会被设置为false,即使它们的结果也是true
开发环境:IntelliJ IDEA 2019.2.2
Spring Boot版本:2.1.8
新建一个名称为demo的Spring Boot项目。
1、pom.xml
加入Thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、src/main/java/com/example/demo/TestController.java