thymeleaf th:表达式总结

1.比较运算符和th:if使用 

gt:great than(大于)>

ge:great equal(大于等于)>=

eq:equal(等于)==

lt:less than(小于)<

le:less equal(小于等于)<=

ne:not equal(不等于)!=

eg:例子应用

<span th:if="${each ne  null}">

      <span> 显示 </span>

<span th:if="${each eq null}">

     <span> 隐藏</span> 

th:object  th:field  th:value 的使用

th:object 

<form name = "frm" th:object="${brand}"   brand是接受后台传过来的对象

th:field

<input name"cgrade" th:field="*{aaa}" type-“text”>   aaa是brand对象中的一个属性

注意:th:field表达式后边跟的是※ { 属性}

th:value

<input type="text" th:value="${brand.bbb}""/> 

 bbb是brand对象中的一个属性  

注意:th:value表达式后边跟的是$ { 对象 .属性}

两者区别:

th:field和th:value都有两种从后台接受值的方式:1、${obj.name} 2、*{name}。需要注意的是,th:field需要有th:object 指定前台传过来的参数,否则浏览器在解析的时候会出现错误。

thymeleaf里的th:field等同于th:name和th:value,浏览器在解析th:field的时候,会解析成name="${th:field}"的值。

然后后台就可以接收到从前台传过来的值。而th:value可以接受到后台的的值,后台则可以根据name获取到前台的值。
 

th:each 循环

用来后台传值前台的值

<span th:each = "each:${集合或数组}> 

<span th:value="${each.属性或者each}"/>

</span>

th:checked 复选框勾选问题

<input type="checkbox" th:value="${属性}" th:checked="${操作}"/>

th:checked="${操作}"的操作如果真 代表该复选框勾选上 假则没有勾选上

th:selected 选择的问题

<select name="属性名" th:field="*{属性}">

<option value="1" th:selected="${#strings.containsIgnoreCase(属性,'1')}">请选择<option>

<option value="2" th:selected="${#strings.containsIgnoreCase(属性,'2')}">111<option>

<option value="3" th:selected="${#strings.containsIgnoreCase(属性,'3')}">222<option>

<option value="4" th:selected="${#strings.containsIgnoreCase(属性,'4')}">333<option>

</select>

猜你喜欢

转载自blog.csdn.net/wqr111/article/details/121948273