前后端遗留问题,改动量太大,所以框架上动最方便,如有更好方法,请各位拿出来学习下,反正我觉得下面这个处理太丑了。
代码
public class MyDateFormart extends SimpleDateFormat {
private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
public MyDateFormart() {
//默认有时间格式
super("yyyy-MM-dd HH:mm:ss");
setTimeZone(TimeZone.getTimeZone("GMT+8"));
}
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
return super.format(date, toAppendTo, fieldPosition);
}
@Override
public Date parse(String source, ParsePosition pos) {
//这边后期可以用模糊匹配方式进行处理
if (StringUtils.isBlank(source))
return null;
Date date = super.parse(source, pos);
if (date == null)
date = simpleDateFormat.parse(source, pos);
return date;
}
}
配置
spring:
jackson:
date-format: com.config.MyDateFormart