注解处理器传递参数改为 Method

This commit is contained in:
click33
2024-08-03 19:22:21 +08:00
parent cd0c20793a
commit c38eb0c68c
18 changed files with 41 additions and 44 deletions

View File

@@ -1,7 +1,6 @@
package com.pj.cases.test;
import cn.dev33.satoken.util.SaResult;
import com.pj.satoken.custom_annotation.CheckAccount;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -16,7 +15,6 @@ public class TestController {
// 测试 浏览器访问: http://localhost:8081/test/test
@RequestMapping("test")
@CheckAccount(name = "sa", pwd = "123456")
public SaResult test() {
System.out.println("------------进来了");
return SaResult.ok();

View File

@@ -6,7 +6,6 @@ import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import cn.dev33.satoken.strategy.SaAnnotationStrategy;
import cn.dev33.satoken.strategy.SaStrategy;
import cn.dev33.satoken.util.SaResult;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -118,9 +117,9 @@ public class SaTokenConfigure implements WebMvcConfigurer {
@PostConstruct
public void rewriteSaStrategy() {
// 重写Sa-Token的注解处理器增加注解合并功能
// SaAnnotationStrategy.instance.getAnnotation = (element, annotationClass) -> {
// return AnnotatedElementUtils.getMergedAnnotation(element, annotationClass);
// };
SaAnnotationStrategy.instance.getAnnotation = (element, annotationClass) -> {
return AnnotatedElementUtils.getMergedAnnotation(element, annotationClass);
};
}
}

View File

@@ -6,7 +6,7 @@ import cn.dev33.satoken.exception.SaTokenException;
import com.pj.satoken.custom_annotation.CheckAccount;
import org.springframework.stereotype.Component;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* 注解 CheckAccount 的处理器
@@ -25,7 +25,7 @@ public class CheckAccountHandler implements SaAnnotationAbstractHandler<CheckAcc
// 每次请求校验注解时,会执行的方法
@Override
public void checkMethod(CheckAccount at, AnnotatedElement element) {
public void checkMethod(CheckAccount at, Method method) {
// 获取前端请求提交的参数
String name = SaHolder.getRequest().getParamNotNull("name");
String pwd = SaHolder.getRequest().getParamNotNull("pwd");

View File

@@ -6,7 +6,7 @@ import com.pj.satoken.StpUserUtil;
import com.pj.satoken.custom_annotation.SaUserCheckLogin;
import org.springframework.stereotype.Component;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* 注解 SaUserCheckLogin 的处理器
@@ -22,7 +22,7 @@ public class SaUserCheckLoginHandler implements SaAnnotationAbstractHandler<SaUs
}
@Override
public void checkMethod(SaUserCheckLogin at, AnnotatedElement element) {
public void checkMethod(SaUserCheckLogin at, Method method) {
SaCheckLoginHandler._checkMethod(StpUserUtil.TYPE);
}

View File

@@ -6,7 +6,7 @@ import com.pj.satoken.StpUserUtil;
import com.pj.satoken.custom_annotation.SaUserCheckPermission;
import org.springframework.stereotype.Component;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* 注解 SaUserCheckPermission 的处理器
@@ -22,7 +22,7 @@ public class SaUserCheckPermissionHandler implements SaAnnotationAbstractHandler
}
@Override
public void checkMethod(SaUserCheckPermission at, AnnotatedElement element) {
public void checkMethod(SaUserCheckPermission at, Method method) {
SaCheckPermissionHandler._checkMethod(StpUserUtil.TYPE, at.value(), at.mode(), at.orRole());
}

View File

@@ -6,7 +6,7 @@ import com.pj.satoken.StpUserUtil;
import com.pj.satoken.custom_annotation.SaUserCheckRole;
import org.springframework.stereotype.Component;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* 注解 SaUserCheckRole 的处理器
@@ -22,7 +22,7 @@ public class SaUserCheckRoleHandler implements SaAnnotationAbstractHandler<SaUse
}
@Override
public void checkMethod(SaUserCheckRole at, AnnotatedElement element) {
public void checkMethod(SaUserCheckRole at, Method method) {
SaCheckRoleHandler._checkMethod(StpUserUtil.TYPE, at.value(), at.mode());
}

View File

@@ -6,7 +6,7 @@ import com.pj.satoken.StpUserUtil;
import com.pj.satoken.custom_annotation.SaUserCheckSafe;
import org.springframework.stereotype.Component;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
/**
* 注解 SaUserCheckPermission 的处理器
@@ -22,7 +22,7 @@ public class SaUserCheckSafeHandler implements SaAnnotationAbstractHandler<SaUse
}
@Override
public void checkMethod(SaUserCheckSafe at, AnnotatedElement element) {
public void checkMethod(SaUserCheckSafe at, Method method) {
SaCheckSafeHandler._checkMethod(StpUserUtil.TYPE, at.value());
}