[Java教程]【Spring】SpringMVC中浅析Date类型数据的传递
0 2016-12-29 21:00:07
在控制器中加入如下代码:@InitBinderpublic void initBinder(ServletRequestDataBinder bin){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置自己的date格式 CustomDateEditor cust = new CustomDateEditor(dsf,true); bin.registerCustomEditor(Date.class,cust);}
这样注解之后,前端传过来的String类型的数据就可以在控制器方法参数中自动转化为Date类型数据:@RequestMapping(value="/index2")public String helloaction2(Date date){ //这里的参数自动将String转化为date类型 return "index";}
原文链接:http://blog.csdn.net/javaloveiphone/article/details/53745068
本文网址:http://www.shaoqun.com/a/283566.html
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:admin@shaoqun.com。
Spring
0