@ControllerAdvice
public class BaseControllerAdvice {
// 初始化绑定
@InitBinder
public void initBinder(WebDataBinder binder) {
//处理表单数据转换对象异常(Date)
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
}
@MappedSuperclass // 配置后,子类可以使用注解
public class BaseEntity implements Serializable {
@Column(name = "CREATE_TIME")
@Temporal(TemporalType.TIMESTAMP) // 实体类会封装成完整的时间“yyyy-MM-dd hh:MM:ss”的Date类型。
@DateTimeFormat(pattern="yyyy-MM-dd")
private Date creteTime; // 创建时间
}
@RequestMapping("/testDate")
public void testDate(@DateTimeFormat(pattern="yyyy-MM-dd") Date mydate){
System.out.println(mydate+"============");
}