您的位置:首页 > 编程语言 > Java开发

springmvc时间类型提交转换的问题

2017-04-05 15:40 232 查看
当form表单中的数据是基本类型的时,直接请求action中的url,一点问题都没有。
但是当form表单总有时间类型的数据时,且对应的controller是用一个Java对象来绑定对应form提交的数据时,就会出现问题。无法提交成功。
解决办法:
在对应的controller中新增下面的方法:

[java] view
plain copy

 





/** 

     * form表单提交 Date类型数据绑定 

     * <功能详细描述> 

     * @param binder 

     * @see [类、类#方法、类#成员] 

     */  

@InitBinder    

public void initBinder(WebDataBinder binder) {    

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");    

     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd
");

        dateFormat.setLenient(false);    

        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));    

}  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java springmvc