• org.springframework.validation.BindException 日期转换异常


    因为项目需求

    要填写时间格式为yyyy-MM-dd

    而数据库的是yyyy-MM-dd   HH:mm:ss

    出现如下错误:

    1.017-09-06 15:43:57.756 [http-bio-69541-exec-8] ERROR COMMON-ERROR[28] - ""

    2.org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 3 errors

    3.Field error in object 'fund' on field 'endRaising': rejected value [2017-09-05]; codes [typeMismatch.fund.endRaising,typeMismatch.endRaising,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [fund.endRaising,endRaising]; arguments []; default message [endRaising]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endRaising'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @com.alibaba.fastjson.annotation.JSONField @javax.persistence.Column java.util.Date for value '2017-09-05'; nested exception is java.lang.IllegalArgumentException: Unable to parse '2017-09-05']

    4.Field error in object 'fund' on field 'foundTime': rejected value [2017-09-04]; codes [typeMismatch.fund.foundTime,typeMismatch.foundTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [fund.foundTime,foundTime]; arguments []; default message [foundTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'foundTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @com.alibaba.fastjson.annotation.JSONField @javax.persistence.Column java.util.Date for value '2017-09-04'; nested exception is java.lang.IllegalArgumentException: Unable to parse '2017-09-04']

    5.Field error in object 'fund' on field 'startRaising': rejected value [1970-01-21]; codes [typeMismatch.fund.startRaising,typeMismatch.startRaising,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [fund.startRaising,startRaising]; arguments []; default message [startRaising]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'startRaising'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @com.alibaba.fastjson.annotation.JSONField @javax.persistence.Column java.util.Date for value '1970-01-21'; nested exception is java.lang.IllegalArgumentException: Unable to parse '1970-01-21']

    解决办法:

        一个一个的转换

    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
    Date estab = sdf.parse(establishmenttime);//成立 时间
    fund.setFoundTime(estab);
    Date start = sdf.parse(starttime);//开始时间
    fund.setStartRaising(start);
    Date end = sdf.parse(endtime);//结束时间
    fund.setEndRaising(end);
    fund.setCompref(standard);
    fund.setFundMoneyTypeEnum(incomeType);
    Result result = fundService.saveorUpdateFundDF(fund, introFile);

    或者  前端传参数  改成    yyyy-MM-dd   HH:mm:ss 格式传入

     或者在实体类接受get set方法里面直接转换  由String接收  return  返回Date类型

     

  • 相关阅读:
    编译原理:算符优先分析
    编译原理:自下而上语法分析
    编译原理:实验二 递归下降语法分析
    编译原理:LL(1)文法的判断,递归下降分析程序
    作业9 DFA最小化
    作业8 非确定的自动机NFA确定化为DFA
    作业7 正规式到正规文法与自动机
    作业6 正规文法与正规式
    作业5 词法分析程序的设计与实现
    作业4 文法和语言总结与梳理
  • 原文地址:https://www.cnblogs.com/liaohongbin/p/7505823.html
Copyright © 2020-2023  润新知