【问题标题】:Why does my th:each not work in my div? Thymleaf为什么我的 th:each 在我的 div 中不起作用?百里香叶
【发布时间】:2021-12-29 03:40:36
【问题描述】:

我正在尝试 th:text 在我的 div 中,但它似乎不起作用

我尝试用一​​个表来做,我得到了我需要的数据,但是当我把它放在一个 div 中时它不起作用

     <div class="info"  data-th-each="shoes: ${shoesList}">
          <p th:text="$(shoes.name)"></p>
          <p th:text="$(shoes.description)"></p>
          <p th:text="$(shoes.price)"></p>          
      </div>

这很有效

<table>

      <tr data-th-each="shoes : ${shoesList}">    
        <td th:text="${shoes.name}"></td>
        <td th:text="${shoes.description}"></td>
        <td th:text="${shoes.price}"></td>
      </tr>        
  
</table>

【问题讨论】:

    标签: java spring-boot thymeleaf backend


    【解决方案1】:

    我认为,它会遵循以下方式 (将 $(shoes.name) 改成 ${shoes.name} )

    <div class="info"  th:each="shoes : ${shoesList}">
          <p th:text="${shoes.name}"></p>
          <p th:text="${shoes.description}"></p>
          <p th:text="${shoes.price}"></p>          
      </div>
    

    请访问此链接 Iteration thymeleaf

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 1970-01-01
      相关资源
      最近更新 更多