From 6818ed062df0d7b48f52cf5374c7a8a000669f93 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 26 Nov 2019 17:26:50 +0800 Subject: [PATCH] 2.5.6 --- .../sop/servercommon/bean/ServiceContext.java | 1 + .../SpringMvcServiceConfiguration.java | 5 +++++ .../mapping/ApiMappingHandlerMapping.java | 9 +++++++-- .../mapping/ApiMappingStringValueResolver.java | 7 ++++++- .../mapping/ApiMappingStringValueResolverMVC.java | 14 ++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolverMVC.java diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java index 2bef4145..16e8520f 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/bean/ServiceContext.java @@ -13,6 +13,7 @@ public class ServiceContext extends ConcurrentHashMap { public static final String REQUEST_KEY = "request"; public static final String RESPONSE_KEY = "response"; public static final String OPEN_CONTEXT_KEY = "openContext"; + public static final String SOP_MVC = "sop.mvc"; public static final String RESTFUL_KEY = "sop-restful"; diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java index 62228425..af4ed868 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/configuration/SpringMvcServiceConfiguration.java @@ -1,6 +1,7 @@ package com.gitee.sop.servercommon.configuration; import com.gitee.sop.servercommon.bean.ServiceConfig; +import com.gitee.sop.servercommon.bean.ServiceContext; import com.gitee.sop.servercommon.manager.EnvironmentContext; import com.gitee.sop.servercommon.manager.ServiceRouteController; import com.gitee.sop.servercommon.mapping.ApiMappingHandlerMapping; @@ -22,6 +23,10 @@ import javax.annotation.PostConstruct; @Slf4j public class SpringMvcServiceConfiguration { + static { + System.setProperty(ServiceContext.SOP_MVC, "true"); + } + public SpringMvcServiceConfiguration() { ServiceConfig.getInstance().getI18nModules().add("i18n/isp/bizerror"); } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java index 506704b6..074cead3 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingHandlerMapping.java @@ -3,6 +3,7 @@ package com.gitee.sop.servercommon.mapping; import com.gitee.sop.servercommon.annotation.ApiAbility; import com.gitee.sop.servercommon.annotation.ApiMapping; import com.gitee.sop.servercommon.bean.ServiceConfig; +import com.gitee.sop.servercommon.bean.ServiceContext; import org.springframework.core.PriorityOrdered; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.util.StringValueResolver; @@ -18,13 +19,17 @@ import java.lang.reflect.Method; public class ApiMappingHandlerMapping extends RequestMappingHandlerMapping implements PriorityOrdered { private static StringValueResolver stringValueResolver = new ApiMappingStringValueResolver(); + private static StringValueResolver stringValueResolverMVC = new ApiMappingStringValueResolverMVC(); @Override protected RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { + String sopMvc = System.getProperty(ServiceContext.SOP_MVC); + boolean isMvc = sopMvc != null; ApiMapping apiMapping = method.getAnnotation(ApiMapping.class); + ApiAbility apiAbility = method.getAnnotation(ApiAbility.class); StringValueResolver valueResolver = null; - if (apiMapping != null) { - valueResolver = stringValueResolver; + if (apiMapping != null || apiAbility != null) { + valueResolver = isMvc ? stringValueResolverMVC : stringValueResolver; } this.setEmbeddedValueResolver(valueResolver); return super.getMappingForMethod(method, handlerType); diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java index da448bab..0e394d7b 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolver.java @@ -7,8 +7,13 @@ import org.springframework.util.StringValueResolver; */ public class ApiMappingStringValueResolver implements StringValueResolver { + private static final String END = "/"; + @Override public String resolveStringValue(String strVal) { - return strVal; + if (strVal == null) { + return null; + } + return strVal + END; } } diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolverMVC.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolverMVC.java new file mode 100644 index 00000000..9e5da2be --- /dev/null +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/mapping/ApiMappingStringValueResolverMVC.java @@ -0,0 +1,14 @@ +package com.gitee.sop.servercommon.mapping; + +import org.springframework.util.StringValueResolver; + +/** + * @author tanghc + */ +public class ApiMappingStringValueResolverMVC implements StringValueResolver { + + @Override + public String resolveStringValue(String strVal) { + return strVal; + } +}