Thymeleaf的th
2024-10-18 17:36:45
th:action 定义后台控制器路径,类似<form>标签的action属性。
<form id="login-form" th:action="@{/login}">...</form>
th:each 对象遍历,功能类似jstl中的<c:forEach>标签。
<form id="login-form" th:action="@{/addStudent}" th:object="${stuReqBean}" method="POST">
<div class="student" th:each="stuIter,rowStat:${stuReqBean.students}">
<input type="text" class="firstName" value="" th:field="*{students[__${rowStat.index}__].firstName}"/>
...
</div></form>
上面的例子中通过选择表达式*{}既能将表单绑定到后台的StudentRequestBean中的集合属性students,也能将Servlet上下文中的StudentRequestBean中的List类型的students变量回显,回显时通过th:each进行遍历。
注意1:绑定集合属性元素下标的用法*{students[__${rowStat.index}__].firstName}
注意2:如果List<Student> students为null,页面将无法显示表单,后台必须给students初始化一个值
注意3:stuIter代表students的迭代器
th:field 常用于表单字段绑定。通常与th:object一起使用。 属性绑定、集合绑定。
<form id="login-form" th:action="@{/login}" th:object="${loginBean}">...
<input type="text" value="" th:field="*{username}"></input>
<input type="text" value="" th:field="*{user[0].username}"></input>
</form>
th:href 定义超链接,类似<a>标签的href 属性。value形式为@{/logout}
<a th:href="@{/logout}" class="signOut"></a>
th:id div id声明,类似html标签中的id属性。
<div class="student" th:id = "stu+(${rowStat.index}+1)"></div>
th:if 条件判断。
<div th:if="${rowStat.index} == 0">... do something ...</div>
th:fragment 我们可以使用th:fragment属性来定义一个模板,声明定义该属性的div为模板片段,常用与头文件、页尾文件的引入。常与th:include,th:replace一起使用。
例如:声明模板片段/WEBINF/templates/footer. html
<div th: fragment=" copy" >
2011 The Good Thymes Virtual Grocery
</div>
引入模板片段
<div th: include=" /templates/footer : : copy" ></div>
<div th: replace=" /templates/footer : : copy" ></div>
th:include 加载模板的内容
见上
th:replace 替换当前标签为模板的中标签
见上
th:object 用于表单数据对象绑定,将表单绑定到后台controller的一个JavaBean参数。常与th:field一起使用进行表单数据绑定
<form id="login-form" th:action="@{/login}" th:object="${loginBean}">...</form>
th:src 用于外部资源引入,类似于<script>标签的src属性,常与@{}一起使用。
<script th:src="@{/resources/js/jquery/jquery.json-2.4.min.js}"
th:value 用于标签复制,类似<option>标签的value属性。
<option th:value="Adult">Adult</option>
<input id="msg" type="hidden" th:value="${msg}" />
th:remove 删除代码
- all 删除当前标签和其内容和子标签
- body 不删除当前标签,但是删除其内容和子标签
- tag 删除当前标签,但不删除子标签
- all-but-first 删除除第一个子标签外的其他子标签
- none 啥也不干
<a href="/something" th:remove="${condition}? tag : none">Link text not to be removed</a>
<table> <tr th:remove="all"> <td>Mild Cinnamon</td> </tr> </table>
最新文章
- easyUi datagrid 返回时间格式化操作
- php读取大文件
- var 的使用
- bzoj4305: 数列的GCD
- spring之BeanFactoryAware接口
- linux设备驱动概述,王明学learn
- 【转】如果成为一个牛比的BI售前
- tableviewCell折叠状态3
- NOIP2010 关押罪犯 (并查集)
- ThinkPHP第二十三天(Category表结构、PHPExcel导入数据函数)
- Bootstrap 图标
- history对象 back() forward() go() 和pushState() replaceState()
- 一个简单的ruby生成器例子(用连续体Continuation实现)
- 回溯法解n皇后问题
- 潭州课堂25班:Ph201805201 并发(进程,线程)二 第十二课 (课堂笔记
- 基于react的记账簿开发
- TRichEdit怎样新增的内容到最后一行?
- java 泛型中class<;T>; 和T的区别是什么?
- ubuntu14.04(server amd64)免密码sudo
- 团队作业1——团队展示&;教辅宝
热门文章
- zabbix、Cacti、Nagios、open-falcon、Ganglia、Prometheus开源监控比较
- 手把手为大家演示fat32转ntfs操作过程,一看就会
- Boom 3D的本地音乐播放功能大放送
- 下载器Folx的创建种子功能怎么使用
- word边框+底纹
- zabbix 监控ssh 登入与报警!!!!
- 痞子衡嵌入式:探析开启CRC完整性校验的IAR工程生成.out和.bin文件先后顺序
- dubbo与zk
- .NET使用AutoResetEvent实现多线程打印奇偶数
- C语言中 EXIT_FAILURE和EXIT_SUCCESS