反射获取所有属性名,判断属性上是否有此注解以及注解的值,
Field[] fields = TableMainAddVO.class.getDeclaredFields(); List<String> strList = new ArrayList<String>(); Arrays.stream(fields).forEach(f -> { if(f.isAnnotationPresent(ApiModelProperty.class)){ ApiModelProperty annotation = f.getAnnotation(ApiModelProperty.class); String value = annotation.value(); strList.add(value+":"+f.getName()); } });
获取所有父级对象
private static <T> List<Class> getAllSupClass(Class l){ List<Class> list1 = new ArrayList<>(); Class allSupClass=getSupClass(l); while (allSupClass!=null){ list1.add(allSupClass); allSupClass=getSupClass(allSupClass); } list1.add(l); return list1; } private static <T> Class getSupClass(Class l){ Class<? super T> aClass = l.getSuperclass(); if(!aClass.getName().contains("Object")){ return aClass; }else { return null; } }