增加参数自动校验位置

This commit is contained in:
wenc000 2020-05-13 17:06:59 +08:00
parent 16adee1c52
commit e9d8315ef0

View File

@ -46,6 +46,14 @@ public class ApiParamsAspect {
public void oauthCutPoint() {
}
@Pointcut("execution(public * com.cm.common.article.controller..*.*(..))")
public void articleCutPoint() {
}
@Pointcut("execution(public * com.cm.common.wechat.controller..*.*(..))")
public void wechatCutPoint() {
}
@Before("apiCutPoint()")
public void beforeApiCutPoint(JoinPoint joinPoint) throws ParamsException {
beforeCutPoint(joinPoint);
@ -61,6 +69,16 @@ public class ApiParamsAspect {
beforeCutPoint(joinPoint);
}
@Before("articleCutPoint()")
public void beforeArticleCutPoint(JoinPoint joinPoint) throws ParamsException {
beforeCutPoint(joinPoint);
}
@Before("wechatCutPoint()")
public void beforeWechatCutPoint(JoinPoint joinPoint) throws ParamsException {
beforeCutPoint(joinPoint);
}
private void beforeCutPoint(JoinPoint joinPoint) throws ParamsException {
Signature signature = joinPoint.getSignature();
Object[] args = joinPoint.getArgs();
@ -73,10 +91,10 @@ public class ApiParamsAspect {
if (method.isAnnotationPresent(CheckRequestBodyAnnotation.class)) {
LOG.debug("校验参数");
Parameter[] parameters = method.getParameters();
for(Parameter parameter : parameters) {
if(parameter.isAnnotationPresent(RequestBody.class)) {
for(Object arg: args) {
if(parameter.getType() == arg.getClass()) {
for (Parameter parameter : parameters) {
if (parameter.isAnnotationPresent(RequestBody.class)) {
for (Object arg : args) {
if (parameter.getType() == arg.getClass()) {
AnnotationUtil.checkField(arg);
}
}