'Is it possible to have an input path for variables in Thymeleaf

I know the title might be misleading but here my question: In Thymeleaf we set request params with the input (in HTML). Is it possible to have an input field that sets the path variable. For example I have an method like this:

@PostMapping("/house/{id}/rent")
    public String rentHouse(@RequestParam Date startDate, @PathVariable("id") long id, Model model) {
        House h = new House();
        h.setId(id);
        r.setStartDate(startDate);
        Rents rents = rentsService.createNewRent(h, id);

        model.addAttribute("rent", rents);
        return "House";
    }

And in House.html I want something like this:

<form th:action="@{/house/${id}/rent/}" method="post">
    <label for="startDate">start Date:</label><br>
    <input type="datetime-local" id="startDate" th:name="startDate" placeholder="startDate"><br>
  <label for="id">house id:</label><br>
    <input type="number" id="id" th:name="id" placeholder="id"><br>
    <br>
    <input type="submit" value="Submit">
    <input type="reset" value="Reset">

So that when I input something then the result url should be looking like this (I know start Date has false format): localhost:8080/House/12/rents?startDate=02.21.22

And is it also possible to pass request body in Thymeleaf, I searched for similar questions but they all solved it by manually putting the path variable in the url. Thanks in advance



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source