freemarker常用属性

 1、th:action

   定义后台控制器的路径,类似<form>标签的action属性。 示例如下。
<form id="login" th:action="@{/login}">......</form>
2、th:each
对对象集合进行遍历输出,和jstl中的<c: forEach>类似,而且这个属性不仅可以循环集合,还可以循环数组及Map,示例如下。
<ol>  
            <li>List类型的循环:  
                <table >  
                  <tr>  
                    <th>用户名</th>  
                    <th>用户邮箱</th> 
                  </tr>  
                  <tr  th:each="user,iterStat : ${list}">  
                    <td th:text="${user.userName}">张三</td>  
                    <td th:text="${user.email}">[email protected]</td>
                  </tr>  
                </table>  
            </li>  
            <li>Map类型的循环:  
                <div th:each="mapS:${map}">  
                <div th:text="${mapS}"></div>  
                </div>  
            </li>  
            <li>数组的循环:  
                <div th:each="arrayS:${arrays}">  
                <div th:text="${arrayS}"></div>  
                </div>  
            </li>  
</ol> 
iterStat还有${iterStat.index}、${iterStat.count}等属性,其属性的含义为:
    index:当前迭代对象的index(从0开始计算)
count: 当前迭代对象的index(从1开始计算)
size:被迭代对象的大小
current:当前迭代变量
even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
first:布尔值,当前循环是否是第一个
last:布尔值,当前循环是否是最后一个

3、th:href
定义超链接,类似<a>标签的href 属性。value形式为@{/login}
<a  class="login" th:href="@{/login}"></a>
4、th:src
用于外部资源引入,类似<script>标签的src属性,常与@{}表达式结合使用。
<script th:src="@{/static/js/jquery-2.4.min.js}"></script>
5、th:id
类似html标签中的id属性。
<div class="user" th:id = "(${index})"></div>
6、th:if
用于进行判断
<span th:if="${num} == 1" >
       <input type="redio" name="se"  th:value="男" />
</span>
<span th:if="${num} == 2">
        <input type="redio" name="se"  th:value="女"  />
</span>
7、th:value
类似html中的value属性,能对某元素的value属性进行赋值。
<input type="hidden" id="vd" name="vd" th:value="${value}">
8、th:text
用于文本的显示
<input type="text" id="username" name="username" th:text="${username}">
9、th:attr
用于给HTML中某元素的某属性赋值。比如例子7还可以写成如下形式.
<input type="hidden" id="vd" name="vd" th:attr="value=${value}" >
10、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>

猜你喜欢

转载自www.cnblogs.com/kingsonfu/p/10390935.html