Spring Boot Get Value of object from select using thymeleaf

Viewed 294

So I have this project, and I want to return an object, from the previous choice of 2 select items. How can I do it? for example:

<select class="form-control" id="cityPicker1">
        <option value="0">select option</option>
        <option th:each="city: ${listCities}" th:value="${city.number}" th:text="${city.name}"></option>
    </select>
    
    <select class="form-control" id="cityPicker2">
        <option value="0">select option</option>
        <option th:each="city: ${listCities}" th:value="${city.number}" th:text="${city.name}"></option>
    </select>

I want to display an item from another item list which has a number1 field and a number2 something like ticket.number1 and ticket.number2 but they have to match the values from the previous selects. I can't seem to find anything. Any ideas?

This is how I set it up in the controller:

@GetMapping("/tickets")
public String viewTicketsPage(Model model) {
    List<City> listCities = cityRepo.findAll();
    List<Ticket> listTickets = ticketRepo.findAll();
    model.addAttribute("listCities", listCities);
    model.addAttribute("listTickets", listTickets);
    return "tickets";
}
1 Answers

I need to clarify a few things about your question. 1 - did you manage to get the checkboxes to work? 2 - can you send the selected data to the controller?

you need a controller to receive data from the page, send this data to the repository to fetch other data..

I believe you want to select a table, where the data matches the selected ones. .

take a look at JPQL, maybe this will help you: https://www.baeldung.com/spring-data-jpa-query

Related