<form th:action="@{/hi}" th:object="${datum}" method="post">
<p>date : <input type="date" th:field="*{date}"/> </p>
<p><input type="submit" value="Submit" /> <input type="reset" value="Reset" /></p>
</form>
Controller for form above
@PostMapping("/hi")
fun testum(@ModelAttribute datum: Datum) {
println(datum)
}
simple pojo class
class Datum(
@DateTimeFormat(pattern = "yyyy-MM-dd")
var date: LocalDate? = null
)
I am trying to send date in form but get this exception:
Resolved exception caused by Handler execution: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'datum' on field 'date': rejected value [2018-06-20]; codes [typeMismatch.datum.date,typeMismatch.date,typeMismatch.java.time.LocalDate,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [datum.date,date]; arguments []; default message [date]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.time.LocalDate' for property 'date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [java.time.LocalDate] for value '2018-06-20'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2018-06-20]]
But if I change type from LocalDate to String it works fine. I want to map date that is in form to date property of Datum class. can anyone help me with that? any links? thanks.
This link did not help me similar problem

