From dd86d2f81ddf30094514c594f9c562213b899e9e Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Sat, 8 Jan 2022 11:12:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.1.6=E3=80=91=E5=A2=9E=E5=8A=A0Respos?= =?UTF-8?q?neData=E7=9A=84=E5=AD=97=E6=AE=B5=E6=8F=8F=E8=BF=B0=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scanner/api/util/ClassReflectUtil.java | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/util/ClassReflectUtil.java b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/util/ClassReflectUtil.java index 76eb93e4e..51e9a109f 100644 --- a/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/util/ClassReflectUtil.java +++ b/kernel-d-scanner/scanner-api/src/main/java/cn/stylefeng/roses/kernel/scanner/api/util/ClassReflectUtil.java @@ -49,6 +49,60 @@ public class ClassReflectUtil { private final static Map RUN_MAP = new HashMap<>(2); + /** + * 获取ResponseData类型的字段描述,参数clazz是ResponseData的data属性的类型 + * + * @author fengshuonan + * @date 2022/1/7 15:37 + */ + public static Set getResponseDataClassFieldDescription(Class clazz) { + + HashSet responseDataFieldMetadata = new HashSet<>(); + + // 创建ResponseData几个固定的属性描述 + FieldMetadata success = new FieldMetadata(); + success.setMetadataId(IdUtil.fastSimpleUUID()); + success.setChineseName("请求是否成功"); + success.setFieldClassType("Boolean"); + success.setFieldClassPath("java.lang.Boolean"); + success.setFieldName("success"); + responseDataFieldMetadata.add(success); + + // 创建ResponseData几个固定的属性描述 + FieldMetadata code = new FieldMetadata(); + code.setMetadataId(IdUtil.fastSimpleUUID()); + code.setChineseName("响应状态码"); + code.setFieldClassType("String"); + code.setFieldClassPath("java.lang.String"); + code.setFieldName("code"); + responseDataFieldMetadata.add(code); + + // 创建ResponseData几个固定的属性描述 + FieldMetadata message = new FieldMetadata(); + message.setMetadataId(IdUtil.fastSimpleUUID()); + message.setChineseName("响应信息"); + message.setFieldClassType("String"); + message.setFieldClassPath("java.lang.String"); + message.setFieldName("message"); + responseDataFieldMetadata.add(message); + + // 创建ResponseData几个固定的属性描述 + FieldMetadata data = new FieldMetadata(); + data.setMetadataId(IdUtil.fastSimpleUUID()); + data.setChineseName("响应对象"); + data.setFieldClassType(clazz.getSimpleName()); + data.setFieldClassPath(clazz.getName()); + data.setFieldName("data"); + + // 设置data属性类型具体的元数据 + Set dataFieldMetadata = getClassFieldDescription(clazz); + data.setGenericFieldMetadata(dataFieldMetadata); + + responseDataFieldMetadata.add(data); + + return responseDataFieldMetadata; + } + /** * 获取一个类的所有字段描述 * @@ -305,6 +359,6 @@ public class ClassReflectUtil { } return isPrimitive; - } + }