溫馨提示×

thymeleaf怎么獲取model的值

小億
497
2024-01-09 19:26:28
欄目: 編程語言

在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中設置好了。

1
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女