1spring mvc 日期处理有多种方式,在数据库中日期为dateime,在java实体类中可以设置为String类型,如String createtime
// 添加时间
private String registerTime = DateFormatUtils.format(new Date(),
"yyyy-MM-dd HH:mm:ss");
private String registerTime = DateFormatUtils.format(new Date(),
"yyyy-MM-dd HH:mm:ss");
2.使用注解
如 @DateTimeFormat(pattern = "yyyy-MM-dd")
private Date lastMoTime;
3,要注意的事,在使用注解情况下,客户端传递过来的为string 类型,必须符合这个pattern pattern = "yyyy-MM-dd")(就是注解中定义的),否则将无法匹配参数
private Date lastMoTime;