Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
youjj
cloud-platform
Commits
92bab3a6
Commit
92bab3a6
authored
Jun 14, 2019
by
周健威
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/base-modify' into base-modify
parents
d31ad520
56b174e3
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
222 additions
and
11 deletions
+222
-11
pom.xml
ace-common/pom.xml
+6
-6
BeanValid.java
.../github/wxiaoqi/security/common/annotation/BeanValid.java
+19
-0
SimpleValid.java
...ithub/wxiaoqi/security/common/annotation/SimpleValid.java
+17
-0
PlatformExceptionHandler.java
...oqi/security/common/handler/PlatformExceptionHandler.java
+7
-3
ValidParamAop.java
...ub/wxiaoqi/security/common/support/aop/ValidParamAop.java
+101
-0
ValidatorConfig.java
...iaoqi/security/common/support/config/ValidatorConfig.java
+58
-0
pom.xml
ace-gate/pom.xml
+10
-0
TourGoodVerification.java
...a/com/xxfc/platform/tour/entity/TourGoodVerification.java
+2
-2
TourGoodVerificationBiz.java
...a/com/xxfc/platform/tour/biz/TourGoodVerificationBiz.java
+2
-0
No files found.
ace-common/pom.xml
View file @
92bab3a6
...
@@ -27,7 +27,7 @@
...
@@ -27,7 +27,7 @@
</properties>
</properties>
<dependencies>
<dependencies>
<
!--<
dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-boot-starter-web
</artifactId>
</dependency>
</dependency>
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</dependency>
-->
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-lang3
</artifactId>
<artifactId>
commons-lang3
</artifactId>
...
@@ -53,22 +53,22 @@
...
@@ -53,22 +53,22 @@
<artifactId>
mapper
</artifactId>
<artifactId>
mapper
</artifactId>
<version>
3.4.0
</version>
<version>
3.4.0
</version>
</dependency>
</dependency>
<dependency>
<!--
<dependency>
<groupId>org.springframework</groupId>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<artifactId>spring-beans</artifactId>
<version>5.0.4.RELEASE</version>
<version>5.0.4.RELEASE</version>
</dependency>
</dependency>
-->
<dependency>
<dependency>
<groupId>
com.github.pagehelper
</groupId>
<groupId>
com.github.pagehelper
</groupId>
<artifactId>
pagehelper
</artifactId>
<artifactId>
pagehelper
</artifactId>
<version>
5.0.3
</version>
<version>
5.0.3
</version>
</dependency>
</dependency>
<dependency>
<!--
<dependency>
<groupId>org.springframework</groupId>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<artifactId>spring-web</artifactId>
<version>5.0.4.RELEASE</version>
<version>5.0.4.RELEASE</version>
</dependency>
</dependency>
-->
<!-- fastjson.jar -->
<!-- fastjson.jar -->
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
ace-common/src/main/java/com/github/wxiaoqi/security/common/annotation/BeanValid.java
0 → 100644
View file @
92bab3a6
package
com
.
github
.
wxiaoqi
.
security
.
common
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author libin
* @version 1.0
* @description 复杂类型校验
* @data 2019/6/13 13:42
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
PARAMETER
)
public
@interface
BeanValid
{
Class
<?>[]
value
()
default
{};
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/annotation/SimpleValid.java
0 → 100644
View file @
92bab3a6
package
com
.
github
.
wxiaoqi
.
security
.
common
.
annotation
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* @author libin
* @version 1.0
* @description 简单参数类型校验
* @data 2019/6/13 13:42
*/
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
PARAMETER
)
public
@interface
SimpleValid
{
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/handler/PlatformExceptionHandler.java
View file @
92bab3a6
...
@@ -9,9 +9,13 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
...
@@ -9,9 +9,13 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
(
"com.xxfc.platform"
)
@RestControllerAdvice
(
"com.xxfc.platform"
)
public
class
PlatformExceptionHandler
{
public
class
PlatformExceptionHandler
{
@ExceptionHandler
(
BaseException
.
class
)
@ExceptionHandler
(
value
=
{
BaseException
.
class
,
Exception
.
class
})
public
BaseResponse
baseExceptionHandler
(
BaseException
e
)
{
public
BaseResponse
baseExceptionHandler
(
Exception
e
)
{
return
new
BaseResponse
(
e
.
getStatus
(),
e
.
getMessage
());
if
(
e
instanceof
BaseException
){
BaseException
be
=
(
BaseException
)
e
;
return
new
BaseResponse
(
be
.
getStatus
(),
be
.
getMessage
());
}
return
new
BaseResponse
(
400
,
e
.
getMessage
());
}
}
}
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/support/aop/ValidParamAop.java
0 → 100644
View file @
92bab3a6
package
com
.
github
.
wxiaoqi
.
security
.
common
.
support
.
aop
;
import
cn.hutool.core.util.ArrayUtil
;
import
com.github.wxiaoqi.security.common.annotation.BeanValid
;
import
com.github.wxiaoqi.security.common.annotation.SimpleValid
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
lombok.Data
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
javax.validation.ConstraintViolation
;
import
javax.validation.Validator
;
import
javax.validation.executable.ExecutableValidator
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Parameter
;
import
java.util.Objects
;
import
java.util.Set
;
/**
* @author libin
* @version 1.0
* @description 切面验证
* @data 2019/6/13 13:46
*/
@Aspect
@Data
public
class
ValidParamAop
{
/**
* 复合类型验证器
*/
private
Validator
validator
;
/**
* 简单类型验证器
*/
private
ExecutableValidator
executableValidator
;
@Pointcut
(
"execution(* com.xxfc.platform..rest..*(..))"
)
public
void
validatorExpress
(){}
@Around
(
"validatorExpress()"
)
public
Object
validatorAround
(
ProceedingJoinPoint
proceedingJoinPoint
)
throws
Throwable
{
//获取方法的所有参数
Object
[]
args
=
proceedingJoinPoint
.
getArgs
();
if
(
ArrayUtil
.
isEmpty
(
args
)){
//没有参数,不用验证
return
proceedingJoinPoint
.
proceed
();
}
MethodSignature
methodSignature
=
(
MethodSignature
)
proceedingJoinPoint
.
getSignature
();
Method
currentMethod
=
methodSignature
.
getMethod
();
Parameter
[]
parameters
=
currentMethod
.
getParameters
();
boolean
hashSimpleValid
=
false
;
int
argLength
=
args
.
length
;
for
(
int
i
=
0
;
i
<
argLength
;
i
++){
BeanValid
beanValidAnnotation
=
parameters
[
i
].
getDeclaredAnnotation
(
BeanValid
.
class
);
if
(
Objects
.
nonNull
(
beanValidAnnotation
)){
if
(
args
[
i
].
getClass
().
isArray
()){
Object
[]
arrayArg
=(
Object
[])
args
[
i
];
for
(
Object
item:
arrayArg
){
Set
<
ConstraintViolation
<
Object
>>
validateResult
=
this
.
validator
.
validate
(
item
,
beanValidAnnotation
.
value
());
if
(!
validateResult
.
isEmpty
()){
String
message
=
validateResult
.
iterator
().
next
().
getMessage
();
return
ObjectRestResponse
.
createFailedResult
(
400
,
message
);
}
}
}
else
{
Set
<
ConstraintViolation
<
Object
>>
validateResult
=
this
.
validator
.
validate
(
args
[
i
],
beanValidAnnotation
.
value
());
if
(!
validateResult
.
isEmpty
()){
String
message
=
validateResult
.
iterator
().
next
().
getMessage
();
return
ObjectRestResponse
.
createFailedResult
(
400
,
message
);
}
}
continue
;
}
if
(!
hashSimpleValid
){
SimpleValid
simpleValidAnnotation
=
parameters
[
i
].
getDeclaredAnnotation
(
SimpleValid
.
class
);
if
(
Objects
.
nonNull
(
simpleValidAnnotation
)){
hashSimpleValid
=
true
;
}
}
}
if
(
hashSimpleValid
){
Object
target
=
proceedingJoinPoint
.
getTarget
();
Set
<
ConstraintViolation
<
Object
>>
validResult
=
this
.
executableValidator
.
validateParameters
(
target
,
currentMethod
,
args
);
if
(!
validResult
.
isEmpty
()){
String
message
=
validResult
.
iterator
().
next
().
getMessage
();
return
ObjectRestResponse
.
createFailedResult
(
400
,
message
);
}
}
return
proceedingJoinPoint
.
proceed
();
}
}
ace-common/src/main/java/com/github/wxiaoqi/security/common/support/config/ValidatorConfig.java
0 → 100644
View file @
92bab3a6
package
com
.
github
.
wxiaoqi
.
security
.
common
.
support
.
config
;
import
com.github.wxiaoqi.security.common.support.aop.ValidParamAop
;
import
org.hibernate.validator.HibernateValidator
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
javax.validation.Validation
;
import
javax.validation.Validator
;
import
javax.validation.ValidatorFactory
;
import
javax.validation.executable.ExecutableValidator
;
/**
* @author libin
* @version 1.0
* @description 验证器validator
* @data 2019/6/13 13:48
*/
@Configuration
public
class
ValidatorConfig
{
/**
* 复合类型所用的验证器
* @return Validator
*/
@Bean
public
Validator
validator
(){
// .failFast( true ) 为设置快速错误模式,默认为false
ValidatorFactory
validatorFactory
=
Validation
.
byProvider
(
HibernateValidator
.
class
)
.
configure
()
.
failFast
(
true
)
.
buildValidatorFactory
();
return
validatorFactory
.
getValidator
();
}
/**
* 简单类型所用的验证器
* @return ExecutableValidator
*/
@Bean
public
ExecutableValidator
executableValidator
()
{
return
validator
().
forExecutables
();
}
/**
* 装配验证器切面
* @param validator Bean验证器
* @param executableValidator 简单类型验证器
* @return ValidParamAop
*/
@Bean
public
ValidParamAop
validAop
(
Validator
validator
,
ExecutableValidator
executableValidator
)
{
ValidParamAop
validParamAop
=
new
ValidParamAop
();
validParamAop
.
setValidator
(
validator
);
validParamAop
.
setExecutableValidator
(
executableValidator
);
return
validParamAop
;
}
}
ace-gate/pom.xml
View file @
92bab3a6
...
@@ -101,6 +101,16 @@
...
@@ -101,6 +101,16 @@
<groupId>
com.github.wxiaoqi
</groupId>
<groupId>
com.github.wxiaoqi
</groupId>
<artifactId>
ace-common
</artifactId>
<artifactId>
ace-common
</artifactId>
<version>
2.0-SNAPSHOT
</version>
<version>
2.0-SNAPSHOT
</version>
<exclusions>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
</exclusion>
<exclusion>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-aop
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<groupId>
com.alibaba
</groupId>
...
...
xx-tour/xx-tour-api/src/main/java/com/xxfc/platform/tour/entity/TourGoodVerification.java
View file @
92bab3a6
...
@@ -30,10 +30,10 @@ public class TourGoodVerification implements Serializable {
...
@@ -30,10 +30,10 @@ public class TourGoodVerification implements Serializable {
private
Integer
id
;
private
Integer
id
;
/**
/**
*
日期规格
*
商品规格id
*/
*/
@Column
(
name
=
"spe_id"
)
@Column
(
name
=
"spe_id"
)
@ApiModelProperty
(
value
=
"
日期
规格id"
)
@ApiModelProperty
(
value
=
"
商品
规格id"
)
private
Integer
speId
;
private
Integer
speId
;
/**
/**
...
...
xx-tour/xx-tour-server/src/main/java/com/xxfc/platform/tour/biz/TourGoodVerificationBiz.java
View file @
92bab3a6
...
@@ -28,4 +28,6 @@ public class TourGoodVerificationBiz extends BaseBiz<TourGoodVerificationMapper,
...
@@ -28,4 +28,6 @@ public class TourGoodVerificationBiz extends BaseBiz<TourGoodVerificationMapper,
mapper
.
insertTourGoodVerification
(
tourGoodVerification
);
mapper
.
insertTourGoodVerification
(
tourGoodVerification
);
}
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment