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));
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章