I am new to Java spring and I am learning how to make reservations. I have assignment to make a web application that helps clients to make reservation in certain coffee that they choose.
I have booking form where there is an input for date, time and for how many people is the reservation.
Here is the input field in HTML where I insert only the time.
<input type="time" id="appt" min="09:00" max="21:00"
class="form-control" step="60" name="time">
My question is what type should I make the time parameter in the controller.
Here is also example of the format that is passed for time parameter when I insert 12:00 PM to the input field: time=12:00
What should I change in my controller to make it working?
@PostMapping( "/book")
public String makeReservation(Model model,
@RequestParam Long objectId,
@RequestParam Integer numPersons,
@RequestParam String date,
@RequestParam String time) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate localDate=LocalDate.parse(date,formatter);
LocalDateTime localDateTime = LocalDateTime.parse(time);
return "master-template";
}
Previously, I was using java.sql.Time but now I am trying to parse the string time to LocalDateTime but I get this error:
java.time.format.DateTimeParseException: Text '12:00' could not be parsed at index 0