TA的每日心情 | 开心 2021-12-13 21:45 |
---|
签到天数: 15 天 [LV.4]偶尔看看III
|
方法1:可以使用@ControllerAdvice增强Controller
- @ControllerAdvice
- public class BaseControllerAdvice {
- // 初始化绑定
- @InitBinder
- public void initBinder(WebDataBinder binder) {
- //处理表单数据转换对象异常(Date)
- binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
- }
- }
复制代码
方法2:直接实体类中的字段上加上@DateTimeFormat(pattern="yyyy-MM-dd")
- @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; // 创建时间
- }
复制代码
方法3:直接设置日期数据注解
- @RequestMapping("/testDate")
- public void testDate(@DateTimeFormat(pattern="yyyy-MM-dd") Date mydate){
- System.out.println(mydate+"============");
- }
复制代码
|
|