@Component
public class BaseController {
@InitBinder
public void initBinder(WebDataBinder dataBinder) {
dataBinder.registerCustomEditor(
Date.class,
new PropertyEditorSupport() {
@Override
public void setAsText(String value) {
try {
setValue(new SimpleDateFormat("yyyy-MM-DD HH:mm:ss").parse(value));
} catch (ParseException e) {
setValue(null);
}
}
/* @Override
public String getAsText() {
return new SimpleDateFormat("YYYY-MM-DD HH:mm:ss").format((Date) getValue());
}*/
});
}
}
网友评论