0

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

enter image description here

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>
Cirrus
  • 15
  • 7
  • Split the `size` at every comma, loop over that array and create an `option` element for each one. – f1sh Dec 31 '21 at 00:04
  • Your database design is flawed in the first place, see the following SO question for details: https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad – Shadow Dec 31 '21 at 01:02

1 Answers1

0
<!-- 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>
윤현구
  • 467
  • 7
  • 19