在前端按格式,手写日期可以保存到数据库,但加上日历插件却报错!
HIYIH 2017-08-19 11:47:46 本人菜鸟一枚,正在努力学习中。
情景是这样的:用户填写信息,里面需要填写出生日期
使用了Struts2与Hibernate。
前端jsp利用<input>输入日期数据。
后台,在action层,对应的类继承了ActionSupport类,实现了ModelDriven接口,用以从前端获取数据。
实体类层,有个用户信息的实体类,里面的日期属性:private Date userBirthday。
对应get/set方法:
public Date getUserBirthday() {
return this.userBirthday;
}
public void setUserBirthday(Date userBirthday) {
this.userBirthday = userBirthday;
}
我在前期没加上日历插件,手动输入日期,比如2017-01-01。是可以完全正常向数据库中写入信息的。但问题出在加上一个日历插件之后,日历向日期的输入框内填写的数据格式形如:2017-1-1这样的,再保存就报错了。最开始以为是格式的问题,但是我用JS让插件自动填写到输入框中的日期,自动变为2017-01-01格式,或者选择2017-10-10,点击保存依然报错。
在浏览器显示的错误信息如下:
Type: Status Report
Message: No result defined for action 包名.Action层对应类名 and result input
Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
在控制台错误信息如下:
WARN [http-nio-8080-exec-10] OgnlValueStack:60 - Error setting expression 'userBirthday' with value '[Ljava.lang.String;@4e440a5d'
ognl.MethodFailedException: Method "setUserBirthday" failed for object cn.wishining.entity.UserInformation@7dff1a69 [java.lang.NoSuchMethodException: cn.wishining.entity.UserInformation.setUserBirthday([Ljava.lang.String;)]
*********
Caused by: java.lang.NoSuchMethodException: 包名.用户信息实体类.setUserBirthday([Ljava.lang.String;)
我想知道,插件填写到输入栏中的日期已经被我改为了2017-01-01这种格式,保存却当做字符串型传入而报错。而我自己手动写日期为2017-01-01就可以。这是为什么呢?请问有什么解决方法没有?需要设置Struts还是更换日历插件呢?