为入参做统一的格式化处理,这样就可以不用@DateTimeFormat注解

import org.springframework.format.datetime.DateFormatter;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.InitBinder;


/**
 * 初始化binnder拦截控制器(对请求参数为data类型的做格式化转换)
 *
 * @author weiwei
 * @date 2022/07/21
 */
@ControllerAdvice
public class InitBinderAdviseController {
    @InitBinder
    public void dateTypeBinder(WebDataBinder webDataBinder) {
        //往数据绑定器中添加一个DateFormatter日期转化器。
        webDataBinder.addCustomFormatter(new DateFormatter("yyyy-MM-dd HH:mm:ss"));

    }

}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容