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

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

 

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

/**
     * 解决前端传递的日期参数验证异常
     * @param binder
     * @author hzj
     * @email 153358882@qq.com
     * @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);
    }

 这样 ,你就轻轻松松解决了 前端接口请求直接异常的问题。 

posted @ 2019-08-05 10:06  不了情  阅读(503)  评论(0)    收藏  举报