关于Maven 工程前端时间参数传递异常的处理 ;Spring boot @InitBinder注解

关于后台提供API 在进行数据交互时,由于前台传递时间的参数 导致 Spring boot 工程直接触发异常的解决

直接复制下方代码;拷到你后台控制器里就可以,Spring boot 会自动去校验,【注】该注解仅作用于当前控制器

   /**
     * 解决前端传递的日期参数验证异常
     * @param binder
     * @author hzj
     * @email [email protected]
     * @since 2019-06-12 18:57:34
     */
@InitBinder
    protected void initBinder(WebDataBinder binder) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CustomDateEditor dateEditor = new CustomDateEditor(df, true);
        binder.registerCustomEditor(Date.class,dateEditor);
    }

 

 

你可能感兴趣的:(分享)