[solved] How do I populate a drop down with a list using thymeleaf and spring

  • Post author:
  • Post category:Bugs
  • Post comments:0 Comments
  • Post last modified:November 3, 2021
  • Reading time:1 mins read

How do I populate a drop down with a list using thymeleaf and spring

Solution:

My View

List test = new ArrayList<>();
model.addAttribute("test", test);
List tests = testRepository.findAll();
model.addAttribute("tests", tests);

My HTML

<div class=”col-lg-3″ th:object=”${test}”>

<select class=”form-control” id=”testOrder” name=”testOrder”>

<option value=””>Select Test Order</option>

<option th:each=”test : ${tests}”

th:value=”${test.testCode}”

th:text=”${test.testCode}+’ : ‘+${test.testName}”></option>

</select>

</div>

Hope it helps….

Leave a Reply