方法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+"============");
}

 

相关文章:

  • 2022-12-23
  • 2021-04-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-18
  • 2021-08-07
  • 2022-01-17
  • 2021-04-17
猜你喜欢
  • 2021-06-05
  • 2021-12-06
  • 2021-08-07
  • 2021-08-07
相关资源
相似解决方案