spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错:

Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property ‘expert.birthdate‘; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property ‘birthdate‘: no matching editors or conversion strategy found

解决方法一:

1.使对应Controller控制器继承 extends SimpleFormController 
2.重写initBinder方法   

protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder){
          SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
           dateFormat.setLenient(false);
           binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }  

注意SimpleDateFormat日期格式与页面日期格式要一致!

解决方法二:

Spring3.0以上的SimpleFormController 已经过时了,最新方式是使用@InitBinder注解的方式

在对应的Controller控制器中

    @InitBinder
    protected void init(HttpServletRequest request, ServletRequestDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }

spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'

时间: 2024-11-23 14:45:40

spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'的相关文章

message [Failed to convert property value of type [java.lang.String] to required type [java.util.Date] for property

springmvc前台字符串,后台Date类型字段.时间强转失败 数值:18年12月31日 15:43:21 解决方法,给时间字段加注释 @DateTimeFormat(pattern = "yy年MM月dd日 HH:mm:ss") private Date f_createtime; 原文地址:https://www.cnblogs.com/passedbylove/p/10208108.html

spring3+struts2+hibernate3整合出现的问题,No mapping found for dependency [type=java.lang.String, name='struts.objectFactory.spring.enableAopSupport']

七月 11, 2016 3:49:24 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:EBook' did not find a matching property.七月 11, 2016 3:4

There is no getter for property named 'userId' in 'class java.lang.String'

[ERROR] 2017-01-18 04:37:06:231 cn.dataenergy.common.CenterHandlerExceptionResolver (CenterHandlerExceptionResolver.java:44) - 统一捕获异常: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Th

org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String'

Caused by: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'parentId' in 'class java.lang.String' at org.apache.ibatis.reflection.Reflector.getGetInvoker(Reflector.java:333) at org.apache.ibatis.reflection.Meta

Mybatis问题:There is no getter for property named 'unitId' in 'class java.lang.String'

Mybatis遇到的问题 问题: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'unitId' in 'class java.lang.String' at org.mybatis.spring.MyBatisExceptionTransla

MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'

mybatis3  : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' in 'class java.lang.String 执行sql: mapper.xml文件: <select id="getMaxCode" parameterType="string" resultType="string"> sele

There is no getter for property named &#39;*&#39; in &#39;class java.lang.String&#39;之源码分析

There is no getter for property named '*' in 'class java.lang.String',此错误之所以出现,是因为mybatis在对parameterType="String"的sql语句做了限制,假如你使用<when test="username != null">这样的条件判断时,就会出现该错误,不过今天我们来刨根问底一下. 一.错误再现 想要追本溯源,就需要错误再现,那么假设我们有这样一个sql查询

There is no getter for property named &#39;xxx&#39; in &#39;class java.lang.String

报错信息: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'investTime' in 'class java.lang.String' at org.mybatis.spring.MyBatisExceptionTranslator.tra

spring Caused by: java.lang.SecurityException: Prohibited package name: java.time

六月 09, 2014 1:05:02 下午 org.apache.catalina.core.AprLifecycleListener init 信息: Loaded APR based Apache Tomcat Native library 1.1.29 using APR version 1.4.8. 六月 09, 2014 1:05:03 下午 org.apache.catalina.core.AprLifecycleListener init 信息: APR capabilities