jiangping
2025-06-17 64fa2c33cd645e86d4e2a8c34c7881ea4aa678cf
server/src/main/java/com/doumee/config/mybatis/MyBatisInterceptor.java
@@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.*;
@@ -11,7 +12,9 @@
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
/**
@@ -41,6 +44,7 @@
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
        Object target = invocation.getArgs()[1];
        if(target instanceof MapperMethod.ParamMap) {
            try {
                target = ((MapperMethod.ParamMap) target).get("param1");
@@ -91,20 +95,29 @@
    /**
     * 给属性赋值
     */
    private void setFieldValue(Field field, Object target, Object value) throws Exception {
    private void setFieldValue(Field field, Object target, Object value)   {
        try {
        field.setAccessible(true);
        field.set(target, value);
        field.setAccessible(false);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /**
     * 获取属性值
     */
    private Object getFieldValue(Field field, Object target) throws Exception {
        field.setAccessible(true);
        Object value = field.get(target);
        field.setAccessible(false);
        return value;
    private Object getFieldValue(Field field, Object target)  {
        try {
            field.setAccessible(true);
            Object value = field.get(target);
            field.setAccessible(false);
            return value;
        }catch (Exception e){
            e.printStackTrace();
        }
      return  null;
    }
    /**
@@ -112,7 +125,7 @@
     */
    private LoginUserInfo getLoginUser () {
        try {
                return (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
              return (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        }catch (Exception e){
        }