Home > front end >  How to select specific part in a string from the database Thymleaf
How to select specific part in a string from the database Thymleaf

Time:12-31

I'm still new to thymleaf and i'm trying to figure out how i can select the sizes i've added to the database to my product page

here is how it shows up when i add it to my database

database

my size variable is a string type

private String size;

I want to implement it in my html with thymleaf

<label for="sizes">Choose size:</label>

  <select name="sizes" id="sizes">

   <option value="37">37</option>
   <option value="38">38</option>
   <option value="39">39</option>
   <option value="40">40</option>
   <option value="41">41</option>
   <option value="42">42</option>

  </select>

CodePudding user response:

<!-- first, loop your records -->
<div th:each="row : ${rows}">
   ...
   <label for="sizes">Choose size:</label>

   <!-- i think your size looks like 1:N structure. so you need to add multiple selection.-->
   <select name="sizes" id="sizes" multiple>
      <option th:each="size : ${#strings.arraySplit(row.size, ',')}" th:value="${size}" th:text="${size}">
      </option>
   </select>

</div>
  • Related