springmvc日期参数绑定为null

问题描述:

springmvc在给bean对象的日期属性绑定参数时为空,如下:
[code="java"]
public void save(User user){
//TODO
}
[/code]
User对象中有一个属性birthday,在页面提交的form表单中有
[code="java"]

[/code]
但是当后台打印出user中的属性值时,发现birthday属性为null,其他的属性都可以正确获取。
这是什么原因引起的呢?还是说birthday的格式有问题?貌似都是这个格式吧!
请各位大牛,指点下迷津!

如果你的User.birthday是Date类型,在springmvc中需要自定义属性编辑器,如:
[code="java"]
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
[/code]

用了strust2了吗?处理form的日期类型,貌似得自定义转换类型。