thymeleaf常用属性
转
作者:ITPSC
出处:http://www.cnblogs.com/hjwublog/
th:action
定义后台控制器路径,类似<form>标签的action属性。
例如:
<form id="login-form" th:action="@{/login}">...</form>
th:each
对象遍历,功能类似jstl中的<c:forEach>标签。
例如:
public class StudentRequestBean {private List<Student> students;...}public class Student implements Serializable{private String firstName;private String school;...} @RequestMapping(value = "/addStudent", method = RequestMethod.POST)public String addStudent(@ModelAttribute(value = "stuReqBean") StudentRequestBean stuReqBean,ModelMap model) {...}
<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}"></input><input type="text" class="school" value="" th:field="*{students[__${rowStat.index}__].school}"></input>...</div></form>
上面的例子中通过选择表达式*{}既能将表单绑定到后台的StudentRequestBean中的集合属性students,也能将Servlet上下文中的StudentRequestBean中的List类型的students变量回显,回显时通过th:each进行遍历。
注意1:绑定集合属性元素下标的用法*{students[__${rowStat.index}__].firstName}
注意2:如果List<Student> students为null,页面将无法显示表单,后台必须给students初始化一个值,即:
List<Student > stus = new ArrayList<Student >();stus .add(new Student ());StudentRequestBean.setStudents(stus );
注意3:stuIter代表students的迭代器
th:field
常用于表单字段绑定。通常与th:object一起使用。 属性绑定、集合绑定。
如:
public class LoginBean implements Serializable{...private String username;private List<User> user;...}public class User implements Serializable{...private String username;;...}@RequestMapping(value = "/login", method = RequestMethod.POST)public String login(@ModelAttribute(value = "loginBean") LoginBean loginBean,ModelMap model) {..}
<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:include
见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:object
用于表单数据对象绑定,将表单绑定到后台controller的一个JavaBean参数。常与th:field一起使用进行表单数据绑定。
例如:
public class LoginBean implements Serializable{...}@RequestMapping(value = "/login", method = RequestMethod.POST)public String login(@ModelAttribute(value = "loginBean") LoginBean loginBean,ModelMap model) {...}
<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:replace
见th:fragment
th:text
文本显示。
例如:
<td class="text" th:text="${username}" ></td>
th:value
用于标签复制,类似<option>标签的value属性。
例如:
<option th:value="Adult">Adult</option><input id="msg" type="hidden" th:value="${msg}" />
转载于:https://www.cnblogs.com/honger/p/6876046.html
thymeleaf常用属性相关推荐
- Springboot的thymeleaf常用属性
th:text th:utext 设置元素中的文本内容 th:text对特殊字符进行转义,作为纯文本标签,等价于内联方式[[${ }]] <!-- 使用表达式 --> ...
- Thymeleaf 常用属性
http://www.cnblogs.com/hjwublog/p/5051732.html 转载于:https://www.cnblogs.com/qiuxnlin/p/6639294.html
- SpringBoot中使用Thymeleaf常用功能(一):表达式访问数据
环境搭建: 创建一个Maven项目,按照Maven项目的规范,在src/main/下新建一个名为resources的文件夹,并在下面新建static和templates文件夹. ① 修改pom.xm ...
- 简述模板引擎、常见模板引擎以及Thymeleaf常用指令
模板引擎概念: 是为了解决用户界面(显示)与业务数据(内容)分离而产生的. 它可以生成特定格式的文档,常用的如格式如HTML.xml以及其他格式的文本格式. 场景使用理解:举个栗子---[开会] 在上 ...
- Thymeleaf常用th标签
Thymeleaf常用th标签 关键字 功能介绍 案例 th:id 替换id <input th:id="'xxx' + ${collect.id}"/> th:tex ...
- thymeleaf模板html a标签,Thymeleaf常用语法:模板片断
Thymeleaf常用语法:模板片断 系统中的很多页面有很多公共内容,例如菜单.页脚等,这些公共内容可以提取放在一个称为"模板片断"的公共页面里面,其它页面可以引用这个 " ...
- selenium提取数据之driver对象的常用属性和方法
selenium提取数据之driver对象的常用属性和方法 在使用selenium过程中,实例化driver对象后,driver对象有一些常用的属性和方法 driver.page_source 当前标 ...
- 尚硅谷学习笔记-节点的常用属性和方法
节点的常用属性和方法[图片在末尾] 方法: 通过具体的元素节点调用 getElementsByTagName() 方法,获取当前节点的指定标签名孩子节点 appendChild( oChildNode ...
- Node.js process 模块常用属性和方法
Node.js是常用的Javascript运行环境,本文和大家发分享的主要是Node.js中process 模块的常用属性和方法,希望通过本文的分享,对大家学习Node.js http://www.m ...
最新文章
- 2019年9月2日开学!寒假时间也定了……
- 整个世界都是你的绿幕:这个视频抠图换背景的方法着实真假难辨
- python读取txt数据-Python从文件中读取数据
- 联机日志损坏时的恢复(非正常关闭数据库)
- TCP与UDP网络编程总结(一)
- 前后端分离工程实现 (VUE、JAVA)、附全部源码
- python 微信bot_我如何创建Python Bot自动登录到强制门户
- SAP License:”事后借记”与第三方外币支付处理
- 这款老不死的笔记本,让我涨见识了
- CentOS 9 镜像下载
- 计算机管理 未分配磁盘,磁盘显示未分配怎么办?
- 当红小生酒店施暴性感女星
- docker 部署jenkins + sonarqube + postgresql 代码扫描
- reddit_Reddit如何设计和编码其详尽的愚人节体验,/ r / place
- 探索C++虚函数在g++中的实现
- 51虚拟安卓系统v1.1.0.6-安卓端的虚拟机(支持root,xposed框架)
- CSR867x — 广播数据设置接口以及如何添加厂商数据
- 面试官:你来说一下Spring IOC容器的创建过程
- php生成PDF文件
- python定义一个dog类 类属性有名字_python 基础 12 初识类,类方法,类属性
热门文章
- “Zhuang.Data”轻型数据库访问框架(二)框架的入口DbAccessor对象
- 移动web开发ajax缓存操作
- [leetcode] Pow(x, n)
- Tomcat中两个不同项目共享Session
- [译]ChipMunk 教程1 - 设置
- 使用Qt作窗口截屏(含源码)
- Oracle rac进阶管理专家指导系列文档
- CCNA(Stand-ALONE)Lab 12-Static Routes
- MapReduce基础开发之八HDFS文件CRUD操作
- php定义枚举,PHP中Enum(枚举)用法实例详解