From 9b4433fddf5b401edb0aace8a404ac733b122702 Mon Sep 17 00:00:00 2001
From: 田源 <tianyuan@vci-tech.com>
Date: 星期四, 03 四月 2025 14:35:02 +0800
Subject: [PATCH] 添加非密字段显示
---
Source/BladeX-Tool/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/Source/BladeX-Tool/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java b/Source/BladeX-Tool/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java
new file mode 100644
index 0000000..bc52928
--- /dev/null
+++ b/Source/BladeX-Tool/blade-core-cloud/src/main/java/org/springblade/core/cloud/version/BladeSpringMvcContract.java
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2018-2028, DreamLu All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * Neither the name of the dreamlu.net developer nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * Author: DreamLu 鍗㈡槬姊� (596392912@qq.com)
+ */
+package org.springblade.core.cloud.version;
+
+import feign.MethodMetadata;
+import org.springblade.core.cloud.annotation.ApiVersion;
+import org.springblade.core.cloud.annotation.UrlVersion;
+import org.springblade.core.tool.utils.StringPool;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
+import org.springframework.cloud.openfeign.support.SpringMvcContract;
+import org.springframework.core.annotation.AnnotatedElementUtils;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.http.HttpHeaders;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.List;
+
+/**
+ * 鏀寔 blade-boot 鐨� 鐗堟湰 澶勭悊
+ *
+ * @see org.springblade.core.cloud.annotation.UrlVersion
+ * @see org.springblade.core.cloud.annotation.ApiVersion
+ * @author L.cm
+ */
+public class BladeSpringMvcContract extends SpringMvcContract {
+
+ public BladeSpringMvcContract(List<AnnotatedParameterProcessor> annotatedParameterProcessors, ConversionService conversionService) {
+ super(annotatedParameterProcessors, conversionService);
+ }
+
+ @Override
+ protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) {
+ if (RequestMapping.class.isInstance(methodAnnotation) || methodAnnotation.annotationType().isAnnotationPresent(RequestMapping.class)) {
+ Class<?> targetType = method.getDeclaringClass();
+ // url 涓婄殑鐗堟湰锛屼紭鍏堣幏鍙栨柟娉曚笂鐨勭増鏈�
+ UrlVersion urlVersion = AnnotatedElementUtils.findMergedAnnotation(method, UrlVersion.class);
+ // 鍐嶆灏濊瘯绫讳笂鐨勭増鏈�
+ if (urlVersion == null || StringUtil.isBlank(urlVersion.value())) {
+ urlVersion = AnnotatedElementUtils.findMergedAnnotation(targetType, UrlVersion.class);
+ }
+ if (urlVersion != null && StringUtil.isNotBlank(urlVersion.value())) {
+ String versionUrl = "/" + urlVersion.value();
+ data.template().uri(versionUrl);
+ }
+
+ // 娉ㄦ剰锛氬湪鐖剁被涔嬪墠 娣诲姞 url鐗堟湰锛屽湪鐖剁被涔嬪悗锛屽鐞� Media Types 鐗堟湰
+ super.processAnnotationOnMethod(data, methodAnnotation, method);
+
+ // 澶勭悊 Media Types 鐗堟湰淇℃伅
+ ApiVersion apiVersion = AnnotatedElementUtils.findMergedAnnotation(method, ApiVersion.class);
+ // 鍐嶆灏濊瘯绫讳笂鐨勭増鏈�
+ if (apiVersion == null || StringUtil.isBlank(apiVersion.value())) {
+ apiVersion = AnnotatedElementUtils.findMergedAnnotation(targetType, ApiVersion.class);
+ }
+ if (apiVersion != null && StringUtil.isNotBlank(apiVersion.value())) {
+ BladeMediaType bladeMediaType = new BladeMediaType(apiVersion.value());
+ data.template().header(HttpHeaders.ACCEPT, bladeMediaType.toString());
+ }
+ }
+ }
+
+ /**
+ * 鍙傝�冿細https://gist.github.com/rmfish/0ed59a9af6c05157be2a60c9acea2a10
+ * @param annotations 娉ㄨВ
+ * @param paramIndex 鍙傛暟绱㈠紩
+ * @return 鏄惁 http 娉ㄨВ
+ */
+ @Override
+ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex) {
+ boolean httpAnnotation = super.processAnnotationsOnParameter(data, annotations, paramIndex);
+ // 鍦� springMvc 涓鏋滄槸 Get 璇锋眰涓斿弬鏁颁腑鏄璞� 娌℃湁澹版槑涓篅RequestBody 鍒欓粯璁や负 Param
+ if (!httpAnnotation && StringPool.GET.equals(data.template().method().toUpperCase())) {
+ for (Annotation parameterAnnotation : annotations) {
+ if (!(parameterAnnotation instanceof RequestBody)) {
+ return false;
+ }
+ }
+ data.queryMapIndex(paramIndex);
+ return true;
+ }
+ return httpAnnotation;
+ }
+}
--
Gitblit v1.9.3