I have a form with a input type date to bind with a propery localDatetime in a bean. It is always getting null in the controller. If I change LocalDateTime by Date everything is ok. Any idea what is happening?
Bean :
@Entity
@Table(name = "visits")
public class Visit {
....
@Column(name = "visit_date")
@DateTimeFormat(iso = ISO.DATE_TIME)
private LocalDateTime date;
..
}
View:
<tr>
<td><label>Date:</label></td>
<td><form:input type="date" path="date" /></td>
</tr>
Controller:
@PostMapping("/saveVisit")
public String saveVisit(@ModelAttribute("visit") Visit theVisit, BindingResult result) {
System.out.println("visit " + theVisit.toString());
// visitService.saveVisit(theVisit);
// send over to our form
return "redirect:/pet/showListVisits?petId=" + theVisit.getPet().getPet_id();
}
Result : visit Visit [visit_id=0, pet=Pet [pet_id=1, owner=null, name=null, type=null], date=null, issue=]