|
@@ -7,6 +7,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
@@ -24,6 +25,9 @@ import java.util.Map;
|
|
|
* - 非超级管理员
|
|
|
*/
|
|
|
|
|
|
+/**
|
|
|
+ * 待弃用
|
|
|
+ */
|
|
|
@Aspect
|
|
|
@Component
|
|
|
public class QueryNullCheckAspectV2 {
|
|
@@ -47,19 +51,10 @@ public class QueryNullCheckAspectV2 {
|
|
|
public Object handleQueryNullCheck(ProceedingJoinPoint joinPoint, QueryNullCheckV2 queryNullCheckV2) throws Throwable {
|
|
|
Object[] args = joinPoint.getArgs();
|
|
|
|
|
|
- Class argDao = queryNullCheckV2.dao();
|
|
|
- String argField = queryNullCheckV2.field();
|
|
|
- String argMessage = queryNullCheckV2.message();
|
|
|
-
|
|
|
-
|
|
|
- // 拿不到实例化后的
|
|
|
-
|
|
|
-// Class<?> implClass = argDao.getClass();
|
|
|
-// Method[] methods = implClass.getDeclaredMethods();
|
|
|
-// for (Method method : methods) {
|
|
|
-// System.out.println(method.getName());
|
|
|
-// }
|
|
|
+ Object service = applicationContext.getBean(queryNullCheckV2.service());
|
|
|
|
|
|
+ String argField = queryNullCheckV2.field();
|
|
|
+ String message = queryNullCheckV2.message();
|
|
|
|
|
|
// 获取参数值
|
|
|
Serializable argValue = null;
|
|
@@ -69,8 +64,6 @@ public class QueryNullCheckAspectV2 {
|
|
|
argValue = Convert.toLong(field.get(arg));
|
|
|
if (argValue != null) { break; }
|
|
|
}
|
|
|
- System.out.println("argValue = " + argValue);
|
|
|
- System.out.println("argValue.getClass() = " + argValue.getClass());
|
|
|
|
|
|
/**
|
|
|
* 参数为空 (例如 user_id = null) 时,校验在实体类那里进行,此处不再进行校验
|
|
@@ -80,17 +73,18 @@ public class QueryNullCheckAspectV2 {
|
|
|
// 拿不到 selectById 方法
|
|
|
// 在MyBatis-Plus中,BaseMapper<T>接口中定义的方法(如selectById)是通过MyBatis-Plus框架在运行时动态生成的代理实现的。这些方法并不是直接在DAO接口的实现类中定义的,而是在代理对象中动态创建的。因此,使用Java反射API直接在DAO接口的实现类中查找这些方法是找不到的。
|
|
|
|
|
|
-
|
|
|
-//// queryResultV2 = argDao.getClass().getMethod("selectById", argValue.getClass()).invoke(argDao, argValue);
|
|
|
-// queryResultV2 = argDao.getClass().getMethod("selectById", Serializable.class).invoke(argDao, argValue);
|
|
|
-// System.out.println("queryResultV2 = " + queryResultV2);
|
|
|
-
|
|
|
-
|
|
|
-// // [反向代理] 执行记录非空查询的 service 方法
|
|
|
-// queryResult = (Map<String, Object>) service.getClass().getMethod(serviceMethod, argValue.getClass()).invoke(service, argValue);
|
|
|
-// if (queryResult == null) {
|
|
|
-// return Result.error(ResultEnum.DATABASE_OPERATION_FAILED.getCode(), message);
|
|
|
+// System.out.println(argService);
|
|
|
+// System.out.println(argService.getClass());
|
|
|
+// System.out.println(argService.getClass().getMethods());
|
|
|
+// for (Method method : argService.getClass().getMethods()) {
|
|
|
+// System.out.println("method: " + method);
|
|
|
// }
|
|
|
+
|
|
|
+ queryResultV2 = service.getClass().getMethod("selectById", argValue.getClass()).invoke(service, argValue);
|
|
|
+ if (queryResult == null) {
|
|
|
+ return Result.error(ResultEnum.DATABASE_OPERATION_FAILED.getCode(), message);
|
|
|
+ }
|
|
|
+ System.out.println(queryResultV2);
|
|
|
}
|
|
|
|
|
|
return joinPoint.proceed();
|