解决springmvc关于前台日期作为实体类对象参数类型转换错误的问题-创新互联

页面报错:

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的秦都网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

后台错误:

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关于前台日期作为实体类对象参数类型转换错误的问题-创新互联
分享网址:https://www.cdcxhl.com/article24/ddjdje.html

成都网站建设公司_创新互联,为您提供全网营销推广品牌网站设计域名注册网站制作网站导航网站设计公司

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

网站优化排名