springboot为当前controller重写日期绑定接受前台的日期字符串

springboot为当前controller重写日期绑定接受前台的日期字符串

仅对当前controller生效,只需在当前controller中写一个方法,
实现前端传日期字符串后端只需Date类型接收

	/**
     * 重写日期绑定接受前台的日期字符串
     *
     * @param binder
     */
    @InitBinder
    public void initBinder(ServletRequestDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章