Linux 拨号vps windows公众号手机端

thymeleaf怎么获取model的值

lewis 8年前 (2017-04-11) 阅读数 9 #程序编程
文章标签 Thymeleaf

在Thymeleaf中,可以通过使用${}表达式来获取model中的值。下面是一些示例:

  1. 获取字符串值:

    <span th:text="${modelValue}"></span>

    这将在<span>标签中显示model中名为modelValue的字符串值。

  2. 获取对象属性值:

    <span th:text="${modelObject.property}"></span>

    这将在<span>标签中显示model中名为modelObject的对象的property属性值。

  3. 使用Thymeleaf内置的迭代变量来遍历集合:

    <ul>
        <li th:each="item : ${modelList}" th:text="${item}"></li>
    </ul>
    

    这将在一个无序列表中显示model中名为modelList的集合中的每个元素。

注意:在使用Thymeleaf获取model的值时,需要确保model中的值已经在controller中设置好了。

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门