AOP获取Mybatis的SQL,入参,操作类型
```java
@Aspect
@Component
public class DynamicDataSourceAspect {
@Autowired
private SqlSessionFactory sqlSessionFactory;
//mapper切点
@Pointcut("execution( * com.linkage.xxx.xxx.manager.mapper.manager.*.*(..))")
public void daoAspect() {
}
@After("daoAspect()")
public void showSql(JoinPoint joinPoint) {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
//类路径
String namespace = method.getDeclaringClass().getName();
//方法名
String methodName = method.getName();
Configuration configuration = sqlSessionFactory.getConfiguration();
MappedStatement mappedStatement = configuration.getMappedStatement(
namespace + "." + methodName);
//操作类型
SqlCommandType sqlCommandType = mappedStatement.getSqlCommandType();
System.out.println("type==>" + sqlCommandType);
//sql
String sql = mappedStatement.getBoundSql(null).getSql();
System.out.println("sql==>" + sql);
//入参
Map<String, Object> parameterMap = new HashMap<>();
Object[] args = joinPoint.getArgs();
for (Object o : args) {
System.out.println("params==>" + o);
}
}
}
转载标明出处:https://blog.csdn.net/renhuan28/article/details/123128130