使用Spring MVC3框架时,可能会遇到这个问题,请求后台没有任何响应,页面显示
The request sent by the client was syntactically incorrect 说的意思是:由客户端发送的请求是语法上是不正确的
把spring日志级别调整到debug级别(log4j.logger.org.springframework=DEBUG),终于找出原因了:
Field error in object 'ad' on field 'beginDate': rejected value [2015-6-24 15:50:14]; codes [typeMismatch.ad.beginDate,typeMismatch.beginDate,typeMismatch.java.util.Date,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [ad.beginDate,beginDate]; arguments []; default message [beginDate]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'beginDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.persistence.Column java.util.Date for value '2015-6-24 15:50:14'; nested exception is java.lang.IllegalArgumentException]
说是日期转换错误,bean里用的是date类型,jsp用的input,string类型
解决办法:在bean的getBeginDate方法上加注解:
如果传入的值是yyyy-MM-dd HH:ss:mm类型的,就加@DateTimeFormat(pattern = "yyyy-MM-dd HH:ss:mm")
如果传入的值是yyyy-MM-dd类型的,就加@DateTimeFormat即可
之前解决过,这次又遇到忘记了,写下来作为记录。