There is a method in the controller:
@PostMapping(path = "/{movieId}/session") public String addSession(@PathVariable Long movieId, @RequestBody @Valid AddTimeOfSessionRequest request) { Long id = new AddTimeOfSession(movieSessionService.addTimeOfSession(request)).getTimeOfSessionId(); return "redirect:/gateway-api/api/movies/" + movieId; } those. This method enters json with several fields:
public class AddTimeOfSessionRequest { private final String timeOfSession; private final Long movieId; private final int price; private final Long hallId; public AddTimeOfSessionRequest( @JsonProperty("timeOfSession") String timeOfSession, @JsonProperty("movieId") Long movieId, @JsonProperty("price") int price, @JsonProperty("hallId") Long hallId) { this.timeOfSession = timeOfSession; this.movieId = movieId; this.price = price; this.hallId = hallId; // get методы } and a question how to transfer from the form JSON which would correspond to this class? Let's say the form looks like this:
<form method="post"> <div class="col-sm-6"> <input type="text" id="timeOfSession" class="form-control" placeholder="введите время сеанса"/> </div> <input type="hidden" id="movieId" value="${movieId}" /> <div class="col-sm-6"> <input type="number" id="price" class="form-control" placeholder="введите стоимость билета на сеанс"/> </div> <div class="col-sm-6"> <#list cinemaHalls as cinemaHall> <div class="form-group form-check"> <input type="checkbox" class="form-check-input" id="hallId" name="hallId" value="${cinemaHall.getHallId()}"> <p class="lead">${cinemaHall.getName()}</p> </#list> </div> <div class="col-sm-6"> <button class="btn btn-primary" type="submit">Добавить</button> </div> </form> if each parameter is passed through @RequestParam, then all the rules. but I want to make the code more compact, so I made it into a separate class.