From 385ab9060676f236a3cd5a8b590efea4c11e4152 Mon Sep 17 00:00:00 2001 From: Forget <1771761586@qq.com> Date: Sun, 18 Apr 2021 16:16:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DcutomField=E7=BB=A7=E6=89=BF?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E5=A4=B1=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/power/doc/helper/ParamsBuildHelper.java | 10 +++++----- .../java/com/power/doc/utils/JavaClassUtil.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java index 3a80b5f..c750174 100644 --- a/src/main/java/com/power/doc/helper/ParamsBuildHelper.java +++ b/src/main/java/com/power/doc/helper/ParamsBuildHelper.java @@ -151,11 +151,11 @@ public class ParamsBuildHelper { boolean strRequired = false; int annotationCounter = 0; CustomField customResponseField = responseFieldMap.get(fieldName); - if (customResponseField != null && simpleName.equals(customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp) { + if (customResponseField != null && JavaClassUtil.isTargetChildClass(simpleName,customResponseField.getOwnerClassName()) && (customResponseField.isIgnore()) && isResp) { continue; } CustomField customRequestField = projectBuilder.getCustomReqFieldMap().get(fieldName); - if (customRequestField != null && simpleName.equals(customRequestField.getOwnerClassName()) && (customRequestField.isIgnore()) && !isResp) { + if (customRequestField != null && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName())&& (customRequestField.isIgnore()) && !isResp) { continue; } an: @@ -211,18 +211,18 @@ public class ParamsBuildHelper { } } //cover required - if (customRequestField != null && !isResp && simpleName.equals(customRequestField.getOwnerClassName()) + if (customRequestField != null && !isResp && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName()) && customRequestField.isRequire()) { strRequired = true; } //cover comment String comment = ""; if (null != customRequestField && StringUtil.isNotEmpty(customRequestField.getDesc()) - && simpleName.equals(customRequestField.getOwnerClassName()) && !isResp) { + && JavaClassUtil.isTargetChildClass(simpleName,customRequestField.getOwnerClassName()) && !isResp) { comment = customRequestField.getDesc(); } if (null != customResponseField && StringUtil.isNotEmpty(customResponseField.getDesc()) - && simpleName.equals(customResponseField.getOwnerClassName()) && isResp) { + && JavaClassUtil.isTargetChildClass(simpleName,customResponseField.getOwnerClassName()) && isResp) { comment = customResponseField.getDesc(); } if (StringUtils.isBlank(comment)) { diff --git a/src/main/java/com/power/doc/utils/JavaClassUtil.java b/src/main/java/com/power/doc/utils/JavaClassUtil.java index 7bbf0d6..448c6e2 100644 --- a/src/main/java/com/power/doc/utils/JavaClassUtil.java +++ b/src/main/java/com/power/doc/utils/JavaClassUtil.java @@ -494,4 +494,19 @@ public class JavaClassUtil { return returnType; } } + + public static boolean isTargetChildClass(String sourceClass,String targetClass){ + try { + Class c = Class.forName(sourceClass); + while (c != null){ + if(c.getName().equals(targetClass)){ + return true; + } + c = c.getSuperclass(); + } + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return false; + } }