thymeleaf怎么获取model的值

   2025-02-05 9310
核心提示:在Thymeleaf中,可以通过使用${}表达式来获取model中的值。下面是一些示例:获取字符串值:span th:text=${modelValue}/span这将

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

获取字符串值:

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

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

获取对象属性值:

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

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

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

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

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

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

 
 
更多>同类维修知识
推荐图文
推荐维修知识
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  网站留言