這裏我使用java 1.8的LocalDate類。在我的bean中,我將返回類型作爲LocalDate。我發送的日期是07/01/2017
。當我試圖保存,我得到follwing異常。不能實例化類型的值[簡單類型,類java.time.LocalDate
org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-33) Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class java.time.LocalDate] from String value ('07/01/2017'); no single-String constructor/factory method
at [Source: [email protected]; line: 1, column: 650] (through reference chain: com.pro.bean.ParentBean["Soici"]->com.pro.bean.Soici["fecha_de_solicitud"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class java.time.LocalDate] from String value ('07/01/2017'); no single-String constructor/factory method
at [Source: [email protected]; line: 1, column: 650] (through reference chain: com.pro.bean.ParentBean["Soici"]->com.pro.bean.Soici["fecha_de_solici"])
我看來春天的PropertyEditor問題的問題。看看,你會發現有用的信息在線 –
看看這個答案這將有助於:http://stackoverflow.com/a/14052884/4828463這個答案使用@InitBinder,它允許你設置你自己的編輯器,而不是propertyeditor –