Я использую весенний mvc и Thymeleaf. Вот HTML форма для даты и времени-подборщика:Не удалось преобразовать значение свойства типа 'java.lang.String' в требуемый тип 'java.util.Date' для свойства 'dateOfBirth';
<form action="#" th:action="@{/created}" th:object="${customer}" method="post" class="form-horizontal">
<div class="row edit-form">
<label for="name" class="col-sm-2 control-label text-right">Date of Birth</label>
<div class="col-sm-6">
<input type="date" class="form-control"
th:field="*{dateOfBirth}" th:required="required" id="dateOfBirth"/>
</div>
</div>
</form>
В контроллере я есть:
@RequestMapping(value ="/created",method = RequestMethod.POST)
public String submitNewCustomer(@ModelAttribute Customer customer){
customerService.createNewCustomer(customer);
return "edit";
}
и класс клиента:
@Data
@Entity
public class Customer {
@Id
@GeneratedValue
Long id;
String firstname;
String lastname;
@Temporal(TemporalType.TIMESTAMP)
Date dateOfBirth;
String username;
String password;
}
К сожалению, когда я отправить форму он жалуется на:
Field error in object 'customer' on field 'dateOfBirth': rejected value [2016-12-14]; codes [typeMismatch.customer.dateOfBirth,typeMismatch.dateOfBirth,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [customer.dateOfBirth,dateOfBirth]; arguments []; default message [dateOfBirth]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'dateOfBirth'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@javax.persistence.Temporal java.util.Date] for value '2016-12-14'; nested exception is java.lang.IllegalArgumentException]
Итак, как я могу это исправить?
Он по-прежнему не работает, с той же ошибкой – Salman