1、异常:
"errors":[{"codes":["typeMismatch.memberDto.birthDay","typeMismatch.birthDay","typeMismatch.java.util.Date","typeMismatch"],"arguments":[{"codes":["memberDto.birthDay","birthDay"]
解决方案:全局拦截转换
public class BaseController implements WebBindingInitializer {
@Override
public void initBinder(WebDataBinder binder, WebRequest request) {
DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}
@InitBinder用于在@Controller中标注于方法,表示为当前控制器注册一个属性编辑器或者其他,只对当前的Controller有效
WebBindingInitializer:实现WebBindingInitializer,重写initBinder注册的属性编辑器是全局的属性编辑器,对所有的Controller都有效
自定义springMVC的属性编辑器主要有两种方式,一种是使用@InitBinder标签在运行期注册一个属性编辑器,这种编辑器只在当前Controller里面有效;还有一种是实现自己的 WebBindingInitializer,然后定义一个
AnnotationMethodHandlerAdapter的bean,在此bean里面进行注册
,这种属性编辑器是全局的。