public static void main(String[] args) throws Exception {
Class clazz = Class.forName("com.kcwl.consign.invoice.application.command.ShipperCreateInvoiceCommand");
for (Field field : clazz.getDeclaredFields()) {
System.out.print(field.getName());
System.out.print("|");
ApiModelProperty declaredAnnotation = (ApiModelProperty)field.getDeclaredAnnotations()[0];
System.out.print(declaredAnnotation.value());
System.out.print("|");
String annotationStr = Arrays.stream(field.getDeclaredAnnotations()).map(e -> e.annotationType().getSimpleName()).collect(Collectors.joining());
System.out.print(annotationStr.contains("NotNull") || annotationStr.contains("NotEmpty"));
System.out.println();
}
}
写了个小方法,输出实体类里的字段、注释、是否必填
于 2023-10-13 18:29:36 首次发布