Commit a9ca9687 by s_guodong

优化错误格式时间拦截

parent 063f14ac
...@@ -31,12 +31,16 @@ public class MyDateDeSerialized extends JsonDeserializer { ...@@ -31,12 +31,16 @@ public class MyDateDeSerialized extends JsonDeserializer {
} }
declaredField.setAccessible(true); declaredField.setAccessible(true);
if (StringUtil.isNotEmpty(source)) { if (StringUtil.isNotEmpty(source)) {
Pattern patternAnnotation = declaredField.getAnnotation(Pattern.class);
String format = declaredField.getAnnotation(JsonFormat.class).pattern(); 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); SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
try { try {
date = simpleDateFormat.parse(source); date = simpleDateFormat.parse(source);
} catch (ParseException e) { } catch (ParseException e) {
Pattern patternAnnotation = declaredField.getAnnotation(Pattern.class);
ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message()); ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message());
return null; 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