Spring 3.1 表单与 List绑定
我有一个表单对象
public class TestForm {
private long id;
private List<Date> dates;
// getters and setters for the above
}
,我的控制器有以下内容..
@RequestMapping(value = "/assignDummy", method = RequestMethod.POST)
public @ResponseBody
String assignDates(TestForm frm) {
System.out.println("frm:"+frm.getId()+", date:"+frm.getDates());
return "Everything is fine";
}
我的表单..
<form name="abc" method="post" action="assignDummy.htm">
<input type="text" name="id" value="1000">
<input type="text" name="dates[0]" value="4500000">
<input type="submit">
</form>
我收到以下错误..
无法将“java.lang.String”类型的属性值转换为 属性“dates[0]”需要类型“java.util.Date”;嵌套的 例外是 org.springframework.core.convert.ConversionFailedException:失败 从 java.lang.String 类型转换为 java.util.Date 类型的值 '4500000';嵌套异常是 java.lang.IllegalArgumentException"
任何帮助表示赞赏。 提前致谢
I have a form object
public class TestForm {
private long id;
private List<Date> dates;
// getters and setters for the above
}
And my controller has the following..
@RequestMapping(value = "/assignDummy", method = RequestMethod.POST)
public @ResponseBody
String assignDates(TestForm frm) {
System.out.println("frm:"+frm.getId()+", date:"+frm.getDates());
return "Everything is fine";
}
My form..
<form name="abc" method="post" action="assignDummy.htm">
<input type="text" name="id" value="1000">
<input type="text" name="dates[0]" value="4500000">
<input type="submit">
</form>
I get the following error..
Failed to convert property value of type 'java.lang.String' to
required type 'java.util.Date' for property 'dates[0]'; nested
exception is
org.springframework.core.convert.ConversionFailedException: Failed to
convert from type java.lang.String to type java.util.Date for value
'4500000'; nested exception is java.lang.IllegalArgumentException"
Any help is appreciated.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您试图将字符串放入日期而不进行转换,因此它崩溃了。
您必须使用自定义属性编辑器才能将输入字符串转换为日期。
尝试添加到您的控制器中
You are trying to put a String into Date without converting it, so it crashes.
You have to use a custom property editor in order to convert the input String into a Date.
Try to add in your controller