spring mvc 接受Date类型数据,使用转换

来源:互联网 发布:iphone移动网络开关 编辑:程序博客网 时间:2024/05/20 10:56
在controller中添加这个方法    /**     * TODO:初始化接收的日期类型不然Date接收不到String类型     * @param binder     */    @InitBinder    public void dateBinder(WebDataBinder binder) {        //The date format to parse or output your dates        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        //Create a new CustomDateEditor        CustomDateEditor editor = new CustomDateEditor(dateFormat, true);        //Register it as custom editor for the Date type        binder.registerCustomEditor(Date.class, editor);    }