说明:
本项目是在
在springboot中使用thymeleaf循环
springboot文章23
修改而来
pom.xml文件,核心配置文件等文件,与文章23保持一致,本文只展示最新添加的文件,以减小文章冗余,更容易看出循环的使用方法。
项目:
2.ThymeleafController类添加方法

3.创建ifunless的html文件
- html>
- <html lang="en" xmlns:th="http://www.thymeleaf.org">
- <head>
- <meta charset="UTF-8">
- <title>if-unlesstitle>
- head>
- <body>
- <div style="margin:auto;">
- <h3>if使用:判断条件为true时,显示标签体内容h3>
- <p th:if="${sex=='m'}">性别是男p>
- <p th:if="${isLogin}">已经登录系统p>
-
- <p th:if="${age>20}">年龄大于20p>
-
- <p th:if="${name}">name是“”p>
-
- <p th:if="${isOld}">isOld是nullp>
- div>
- <br/>
- <br/>
- <div style="margin: auto;">
- <h3>unless的使用:判断条件为false时,显示标签体内容h3>
- <p th:unless="${sex=='m'}">性别是男p>
- <p th:unless="${isLogin}">登录系统p>
- <p th:unless="${isOld}">isOld是nullp>
- div>
-
- body>
- html>
4.if-unless的测试

点击判断语句If和unless
二、switch,case判断语句
- html>
- <html lang="en" xmlns:th="http://www.thymeleaf.org">
- <head>
- <meta charset="UTF-8">
- <title>if-unlesstitle>
- head>
- <body>
- <div style="margin:auto;">
- <h3>switch的使用h3>
- <div th:switch="${sex}">
- <p th:case="w">性别是女p>
- <p th:case="m">性别是男p>
- <p th:case="*">性别未知p>
- div>
- div>
-
- body>
- html>

当sex的值为w时

当sex的值既不是m又不是w时
