Thymeleaf th:each

Degiskenler

String[] names = {"dogukan","onur","mehmet"};
model.addAttribute("names", names);

Ornek 1

<ul>
  <li th:each="name:${names}" th:text="${name}">Name</li>
</ul>
<ul>
  <li>dogukan</li>
  <li>onur</li>
  <li>mehmet</li>
</ul>

Ornek 2

<ul>
  <li th:each="name,i:${names}">
    <p th:text="${name}"> Name</p>
    <p th:text="${i.index}">0</p>
    <p th:text="${i.size}">3</p>
      <p th:text="${i.even}">true</p>
    </li>
</ul>
<ul>
  <li>
    <p>dogukan</p>
    <p>0</p>
    <p>3</p>
      <p>false</p>
    </li>
  <li>
    <p>onur</p>
    <p>1</p>
    <p>3</p>
      <p>true</p>
    </li>
  <li>
    <p>mehmet</p>
    <p>2</p>
    <p>3</p>
      <p>false</p>
    </li>
</ul>

 

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *