From 59efb859b021eb803a794502bef0cd77fd561a20 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 6 Aug 2019 20:14:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D@RequestBody=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E7=BB=91=E5=AE=9A=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AlipayServiceConfiguration.java | 10 -------- .../param/ApiArgumentResolver.java | 24 ++++++++++++++++--- .../controller/PostJsonController.java | 3 ++- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java index e35f9237..9525532b 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/AlipayServiceConfiguration.java @@ -3,11 +3,8 @@ package com.gitee.sop.servercommon.configuration; import com.gitee.sop.servercommon.bean.ServiceConfig; import com.gitee.sop.servercommon.param.SopHandlerMethodArgumentResolver; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.method.support.HandlerMethodArgumentResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; -import java.util.List; - /** * 具备支付宝开放平台服务提供能力 * @author tanghc @@ -22,13 +19,6 @@ public class AlipayServiceConfiguration extends BaseServiceConfiguration { @Autowired private RequestMappingHandlerAdapter requestMappingHandlerAdapter; - @Override - protected void addArgumentResolvers(List argumentResolvers) { - super.addArgumentResolvers(argumentResolvers); - SopHandlerMethodArgumentResolver sopHandlerMethodArgumentResolver = ServiceConfig.getInstance().getMethodArgumentResolver(); - argumentResolvers.add(sopHandlerMethodArgumentResolver); - } - @Override protected void doAfter() { super.doAfter(); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java index 38982d29..cc0660e1 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ApiArgumentResolver.java @@ -17,12 +17,15 @@ import org.springframework.web.method.support.ModelAndViewContainer; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; +import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; /** @@ -42,14 +45,29 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { @Override public void setRequestMappingHandlerAdapter(RequestMappingHandlerAdapter requestMappingHandlerAdapter) { this.requestMappingHandlerAdapter = requestMappingHandlerAdapter; + List argumentResolversNew = new ArrayList<>(64); + // 先加自己 + argumentResolversNew.add(this); + HandlerMethodArgumentResolver lastOne = null; + for (HandlerMethodArgumentResolver argumentResolver : Objects.requireNonNull(requestMappingHandlerAdapter.getArgumentResolvers())) { + // RequestResponseBodyMethodProcessor暂存起来,放在最后面 + if (argumentResolver instanceof RequestResponseBodyMethodProcessor) { + lastOne = argumentResolver; + } else { + argumentResolversNew.add(argumentResolver); + } + } + if (lastOne != null) { + argumentResolversNew.add(lastOne); + } + this.requestMappingHandlerAdapter.setArgumentResolvers(argumentResolversNew); } @Override public boolean supportsParameter(MethodParameter methodParameter) { - boolean hasAnnotation = methodParameter.getMethodAnnotation(ApiMapping.class) != null - || methodParameter.getMethodAnnotation(ApiAbility.class) != null; // 有注解 - return hasAnnotation; + return methodParameter.getMethodAnnotation(ApiMapping.class) != null + || methodParameter.getMethodAnnotation(ApiAbility.class) != null; } @Override diff --git a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java index 8bed5cf8..1be5d6d4 100644 --- a/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java +++ b/sop-example/sop-story/sop-story-web/src/main/java/com/gitee/sop/storyweb/controller/PostJsonController.java @@ -6,6 +6,7 @@ import com.gitee.sop.servercommon.bean.OpenContext; import com.gitee.sop.story.api.domain.Story; import com.gitee.sop.storyweb.controller.param.StoryParam; import org.apache.commons.lang3.StringUtils; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.Arrays; @@ -23,7 +24,7 @@ public class PostJsonController { * @return */ @ApiMapping("demo.post.json") - public Story postJson(StoryParam param) { + public Story postJson(@RequestBody StoryParam param) { // 获取开放平台请求参数 OpenContext openContext = ServiceContext.getCurrentContext().getOpenContext(); List params = Arrays.asList( From 22409fc3cc45e2e7155d654c8023911d2d7c67bc Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 6 Aug 2019 20:16:26 +0800 Subject: [PATCH 2/2] 1.13.6 --- changelog.md | 8 ++++++++ sop-admin/sop-admin-server/pom.xml | 2 +- sop-common/pom.xml | 2 +- sop-common/sop-gateway-common/pom.xml | 4 ++-- sop-common/sop-registry-api/pom.xml | 2 +- sop-common/sop-service-common/pom.xml | 4 ++-- sop-example/sop-auth/pom.xml | 2 +- sop-example/sop-book/sop-book-web/pom.xml | 2 +- sop-example/sop-easyopen/pom.xml | 2 +- sop-example/sop-springmvc/pom.xml | 2 +- sop-example/sop-story/sop-story-web/pom.xml | 2 +- sop-gateway/pom.xml | 2 +- sop-website/website-server/pom.xml | 2 +- 13 files changed, 22 insertions(+), 14 deletions(-) diff --git a/changelog.md b/changelog.md index 251584a7..20b59569 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,13 @@ # changelog +## 1.13.6 + +- 修复@RequestBody不能绑定问题 + +## 1.13.5 + +- 修复postJson下version获取不到问题 + ## 1.13.4 - 修复admin服务列表最后更新时间不显示问题 diff --git a/sop-admin/sop-admin-server/pom.xml b/sop-admin/sop-admin-server/pom.xml index b74deaf0..ef289d11 100644 --- a/sop-admin/sop-admin-server/pom.xml +++ b/sop-admin/sop-admin-server/pom.xml @@ -30,7 +30,7 @@ com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-common/pom.xml b/sop-common/pom.xml index b9474842..b72dd887 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT pom diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index 4944f39f..ab38b6f5 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT ../pom.xml sop-gateway-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-registry-api/pom.xml b/sop-common/sop-registry-api/pom.xml index f2aa4b67..90bac2f2 100644 --- a/sop-common/sop-registry-api/pom.xml +++ b/sop-common/sop-registry-api/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT UTF-8 diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index a0b12082..2b409d4e 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT ../pom.xml sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT jar sop-service-common diff --git a/sop-example/sop-auth/pom.xml b/sop-example/sop-auth/pom.xml index 581fb460..07e5753c 100644 --- a/sop-example/sop-auth/pom.xml +++ b/sop-example/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index c1610423..8be2be93 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index ce2fe39c..068140c1 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT org.springframework.cloud diff --git a/sop-example/sop-springmvc/pom.xml b/sop-example/sop-springmvc/pom.xml index 84f68b37..d02be1c7 100644 --- a/sop-example/sop-springmvc/pom.xml +++ b/sop-example/sop-springmvc/pom.xml @@ -20,7 +20,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index c80b2131..7c9a7766 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -24,7 +24,7 @@ com.gitee.sop sop-service-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT com.gitee.sop diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 617820af..e69d3a3c 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -23,7 +23,7 @@ com.gitee.sop sop-gateway-common - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT diff --git a/sop-website/website-server/pom.xml b/sop-website/website-server/pom.xml index 72a66b50..c3f183e9 100644 --- a/sop-website/website-server/pom.xml +++ b/sop-website/website-server/pom.xml @@ -25,7 +25,7 @@ com.gitee.sop sop-registry-api - 1.13.5-SNAPSHOT + 1.13.6-SNAPSHOT