Commit 05b5cf8d by s_guodong

update

parent f411eff0
package com.ceb.gjjs.mda.config; package com.ceb.gjjs.mda.config;
import com.brilliance.eibs.util.StringUtil; import com.brilliance.eibs.util.StringUtil;
import com.brilliance.mda.runtime.annotation.RelPath;
import com.ceb.gjjs.mda.util.ValidatorUtil; import com.ceb.gjjs.mda.util.ValidatorUtil;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonDeserializer;
import javax.validation.constraints.Pattern;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.text.ParseException; import java.text.ParseException;
...@@ -31,17 +31,17 @@ public class MyDateDeSerialized extends JsonDeserializer { ...@@ -31,17 +31,17 @@ 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 msg = declaredField.getAnnotation(RelPath.class).message();
String format = declaredField.getAnnotation(JsonFormat.class).pattern(); String format = declaredField.getAnnotation(JsonFormat.class).pattern();
if (format.length() != source.length()) { if (format.length() != source.length()) {
ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message()); ValidatorUtil.CHECK_ERR_MSG.set(StringUtil.isEmpty(msg) ? "时间格式不正确" : msg);
return null; 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) {
ValidatorUtil.CHECK_ERR_MSG.set(patternAnnotation == null ? "时间格式不正确" : patternAnnotation.message()); ValidatorUtil.CHECK_ERR_MSG.set(StringUtil.isEmpty(msg) ? "时间格式不正确" : msg);
return null; return null;
} }
} }
......
...@@ -3,9 +3,7 @@ package com.ceb.gjjs.mda.util; ...@@ -3,9 +3,7 @@ package com.ceb.gjjs.mda.util;
import com.brilliance.eibs.util.StringUtil; import com.brilliance.eibs.util.StringUtil;
import com.brilliance.mda.runtime.annotation.ListValue; import com.brilliance.mda.runtime.annotation.ListValue;
import com.brilliance.mda.runtime.annotation.Need; import com.brilliance.mda.runtime.annotation.Need;
import com.brilliance.mda.runtime.mda.util.DateUtils;
import com.brilliance.mda.support.jakson.serialize.DecimalLength; import com.brilliance.mda.support.jakson.serialize.DecimalLength;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.Length;
...@@ -171,14 +169,7 @@ public class ValidatorUtil { ...@@ -171,14 +169,7 @@ public class ValidatorUtil {
return "参数校验错误[" + annotation.message() + "]"; return "参数校验错误[" + annotation.message() + "]";
} }
} }
if (f.isAnnotationPresent(JsonFormat.class) && o != null) {
Date date = (Date) o;
JsonFormat annotation = f.getAnnotation(JsonFormat.class);
String format = DateUtils.format(date, annotation.pattern());
if (annotation.pattern().length() != format.length()) {
return "参数校验错误[时间格式不正确]";
}
}
} else if (type.getName().contains("com")) { } else if (type.getName().contains("com")) {
// 对象类型 // 对象类型
String check = check(o); String check = check(o);
......
...@@ -12,14 +12,18 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; ...@@ -12,14 +12,18 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/** /**
* 视图映射注解 * 视图映射注解
*
* @author fukai * @author fukai
*
*/ */
@Documented @Documented
@Retention(RUNTIME) @Retention(RUNTIME)
@Target({TYPE,FIELD}) @Target({TYPE, FIELD})
public @interface RelPath { public @interface RelPath {
String value(); //路径 String value(); //路径
DirType dir() default DirType.BOTH ; //输入输出方向
boolean recursion() default false; //是否递归关联 DirType dir() default DirType.BOTH; //输入输出方向
boolean recursion() default false; //是否递归关联
String message() default "";
} }
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