字段校验工具类
| 22 | * 字段校验工具类 |
| 23 | */ |
| 24 | public class CheckUtils { |
| 25 | |
| 26 | private static String SEPARATOR = "."; |
| 27 | private static String SYSTEM = "trade"; |
| 28 | private static String SUB_OBJECT = "-SUBobject"; |
| 29 | private static String LIST = "java.util.List"; |
| 30 | private static Logger log = LoggerFactory.getLogger(CheckUtils.class); |
| 31 | |
| 32 | /** |
| 33 | * 获取字段和注解相关信息 |
| 34 | * @param objectClazz |
| 35 | * @param annotationClass |
| 36 | * @return k-字段名称 v-注解信息 |
| 37 | */ |
| 38 | private static Map<String, Object> getNotNullInfo(Class<?> objectClazz, Class annotationClass,Set<String> classNameSet, Map<String, Object> getAnnotateInfoMap) { |
| 39 | if(classNameSet == null){ |
| 40 | classNameSet = new HashSet<>(); |
| 41 | } |
| 42 | if(getAnnotateInfoMap == null){ |
| 43 | getAnnotateInfoMap = new HashMap<>(); |
| 44 | } |
| 45 | |
| 46 | String className = objectClazz.getName(); |
| 47 | if(classNameSet.contains(className)){ |
| 48 | return getAnnotateInfoMap; |
| 49 | } |
| 50 | classNameSet.add(className); |
| 51 | // Map<String, Object> getAnnotateInfoMap = new HashMap<>(); |
| 52 | |
| 53 | List<Field> fieldList = TableInfoHelper.getAllFields(objectClazz); |
| 54 | |
| 55 | for (Field field : fieldList) { |
| 56 | Object annotate = field.getAnnotation(annotationClass); |
| 57 | if (annotate != null) { |
| 58 | getAnnotateInfoMap.put(className +SEPARATOR+ field.getName(), annotate); |
| 59 | } |
| 60 | if (List.class.equals(field.getType())) { |
| 61 | Type type = field.getGenericType(); |
| 62 | if (type != null) { |
| 63 | if (type instanceof ParameterizedType) { |
| 64 | ParameterizedType pt = (ParameterizedType) type; |
| 65 | Class sonObjectClass = (Class) pt.getActualTypeArguments()[0]; |
| 66 | Map<String, Object> sonObjectAnnotateInfoMap = getNotNullInfo(sonObjectClass, annotationClass, classNameSet,getAnnotateInfoMap); |
| 67 | |
| 68 | // getAnnotateInfoMap.put(prefix + field.getName() + SUB_OBJECT, sonObjectAnnotateInfoMap); |
| 69 | } |
| 70 | } |
| 71 | } else if (field.getType().toString().contains(SYSTEM)) { |
| 72 | Map<String, Object> sonObjectAnnotateInfoMap = getNotNullInfo(field.getType(), annotationClass, classNameSet,getAnnotateInfoMap); |
| 73 | // getAnnotateInfoMap.put(prefix + field.getName() + SUB_OBJECT, sonObjectAnnotateInfoMap); |
| 74 | } |
| 75 | |
| 76 | |
| 77 | } |
| 78 | return getAnnotateInfoMap; |
| 79 | } |
| 80 | |
| 81 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected