核心思路就是添加一个mybatis的拦截器,由Invocation invocation 拿到需要的参数信息
注意导入的包
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.plugin.*;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
/**
* @author : yzgu
* @description : 自定义 mybatis 拦截器,针对修改数据做记录
* @Version 1.0
* @date : 2021/12/29
*/
@Intercepts({
@Signature(type = Executor.class, method = "update", args = { MappedStatement.class, Object.class })
})
@Component
public class MybatisInterceptor implements Interceptor {
@Override
public Object intercept(Invocation invocation) throws Throwable {
Object[] args = invocation.getArgs();
Class<? extends Invocation> aClass = invocation.getClass();
Method method = invocation.getMethod();
invocation.getTarget();
Object proceed = invocation.proceed();
return proceed;
}
@Override
public Object plugin(Object target) {
return Plugin.wrap(target, this);
}
}