From f62475d3fcd6813a96c7f7fc22e28d5d9e609e6b Mon Sep 17 00:00:00 2001 From: tanghc Date: Wed, 6 Nov 2019 20:26:39 +0800 Subject: [PATCH] =?UTF-8?q?JSR-303=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sop/servercommon/param/ApiArgumentResolver.java | 8 +++----- .../servercommon/param/ServiceParamValidator.java | 12 +++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) 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 97d53c50..82c3be81 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 @@ -129,11 +129,9 @@ public class ApiArgumentResolver implements SopHandlerMethodArgumentResolver { if (paramObj instanceof OpenContext) { paramObj = ((OpenContext) paramObj).getBizObject(); } - if (paramObj != null) { - // JSR-303验证 - paramValidator.validateBizParam(paramObj); - return ret; - } + // JSR-303验证 + paramValidator.validateBizParam(paramObj); + return ret; } HandlerMethodArgumentResolver resolver = getOtherArgumentResolver(methodParameter); if (resolver != null) { diff --git a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java index 109492ad..ede3fdbf 100644 --- a/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java +++ b/sop-common/sop-service-common/src/main/java/com/gitee/sop/servercommon/param/ServiceParamValidator.java @@ -15,6 +15,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Set; /** @@ -70,6 +71,7 @@ public class ServiceParamValidator implements ParamValidator { * 1. 不为基本类型; * 2. 不为java自带的类型; * 3. 不为枚举 + * 4. 不为Map * @param field field * @return true,是自定义的 */ @@ -78,6 +80,9 @@ public class ServiceParamValidator implements ParamValidator { if (fieldType.isPrimitive()) { return false; } + if (Map.class.isAssignableFrom(fieldType)) { + return false; + } Class declaringClass = field.getDeclaringClass(); boolean isEnum = declaringClass == field.getType() && declaringClass.isEnum(); if (isEnum) { @@ -88,7 +93,12 @@ public class ServiceParamValidator implements ParamValidator { return false; } String packageName = aPackage.getName(); - return !SYSTEM_PACKAGE_LIST.contains(packageName); + for (String prefix : SYSTEM_PACKAGE_LIST) { + if (packageName.startsWith(prefix)) { + return false; + } + } + return true; } private RuntimeException getValidateBizParamException(String errorMsg) {