zoukankan      html  css  js  c++  java
  • java-org.springframework.core.convert.ConversionFailedException- 前端传string解析date异常

    关于SpringMVC前台日期作为实体类对象参数类型转换错误解决

    异常信息:

    Field error in object 'tblHouse' on field 'houseTime': rejected value [2018-01-26]; codes [typeMismatch.tblHouse.houseTime,typeMismatch.houseTime,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [tblHouse.houseTime,houseTime]; arguments []; default message [houseTime]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'houseTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.baomidou.mybatisplus.annotations.TableField @org.springframework.format.annotation.DateTimeFormat java.util.Date] for value '2018-01-26'; nested exception is java.lang.IllegalArgumentException: Invalid format: "2018-01-26" is too short]

    异常场景描述

    前端输入框为选择日期的插件,选择日期完成,请求后台添加数据,报错。

    解决方式

    在实体类中的属性上添加该注解,即可解决该错误

       @DateTimeFormat(pattern = "yyyy-MM-dd")
        private Date houseTime;

    参考文章:

    http://www.linuxidc.com/Linux/2017-06/145204.htm

  • 相关阅读:
    白话机器学习
    Intersecting Lines POJ
    Segments POJ
    Toy Storage POJ
    TOYS POJ
    2019CCPC秦皇岛赛区1004 Decimal
    Django 基本使用
    HTML页面布局
    微擎上传视频,音频,图片提示格式不支持
    微擎应用名称图标的修改
  • 原文地址:https://www.cnblogs.com/shaofeer/p/11154363.html
Copyright © 2011-2022 走看看