报错:
org.springframework.core.convert.ConversionFailedException:
Failed to convert from type java.lang.String to type java.util.Date for value ‘2017-12-06‘; nested exception is java.lang.IllegalArgumentException]
解决办法:
在pojo的属性上加注解
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date commentTime;
上面不管用还可以:
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone ="GMT+08")
public Date getCommentTime() {
return commentTime;
}
还可以些配置类:
public class CustomDate implements WebBindingInitializer {
@Override
public void initBinder(WebDataBinder webDataBinder) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
}