I am very new to SpringBoot
. I have some issues converting String value which I get from jsp form to LocalTime.
For example I have jsp form where I write my input:
<div class="col-lg-7">
<form:input path="shiftStart" type="time" name="shiftStart" id="shift-start-time" min="08:00:00" max="17:45:00" step="900"></form:input>
</div>
and I have the following controller where I try to convert this String value to LocalTime variable:
@PostMapping("/add-shift")
public String createShiftForm(@ModelAttribute("shiftForm") @Valid TimeTable timeTable, BindingResult result, Model model, @RequestParam("shiftStart") String shiftStart ){
if (result.hasErrors()) {
return "/add-shift";
}
LocalTime startShift = LocalTime.parse(shiftStart);
model.addAttribute("shiftStart",startShift);
return "redirect:/admin";
}
and I am getting the following error:
Failed to convert property value of type java.lang.String to required type java.time.LocalTime for property shiftEnd; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Column java.time.LocalTime] for value 09:15; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [09:15]
Can anybody please help?