Commit a9ca9687 by s_guodong

优化错误格式时间拦截

parent 063f14ac
......@@ -31,12 +31,16 @@ public class MyDateDeSerialized extends JsonDeserializer {
}
declaredField.setAccessible(true);
if (StringUtil.isNotEmpty(source)) {
Pattern patternAnnotation = declaredField.getAnnotation(Pattern.class);
String format = declaredField.getAnnotation(JsonFormat.class).pattern();
if (format.length() != source.length()) {
ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message());
return null;
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
try {
date = simpleDateFormat.parse(source);
} catch (ParseException e) {
Pattern patternAnnotation = declaredField.getAnnotation(Pattern.class);
ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message());
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment