頁面報錯:
后臺錯誤:
Field error in object 'user' on field 'birthday': rejected value [2013-06-24]; codes [typeMismatch.user.birthday,typeMismatch.birthday,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [user.birthday,birthday]; arguments []; default message [birthday]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birthday'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value '2013-06-24'; nested exception is java.lang.IllegalArgumentException]
解決方案1:在對應的實體類屬性上加入 @DateTimeFormat(pattern = "yyyy-MM-dd")
解決方案2:不使用 <mvc:annotation-driven/>注解
使用 DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 注解驅動配置
在對應的實體類屬性上加入 @DateTimeFormat(pattern = "yyyy-MM-dd")
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="webBindingInitializer"> <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer"> <property name="conversionService"> <bean class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/> </property> </bean> </property> </bean>
網頁題目:解決springmvc關于前臺日期作為實體類對象參數類型轉換錯誤的問題-創新互聯
分享網址:http://vcdvsql.cn/article24/ddjdje.html
成都網站建設公司_創新互聯,為您提供全網營銷推廣、品牌網站設計、域名注冊、網站制作、網站導航、網站設計公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯