@Pointcut("execution(public * sanyang.legal.mapper..*.*(..))")
public void log(){
}
@Autowired
private SqlSessionFactory sqlSessionFactory;
//环绕通知
@Around("log()")
public Object around(ProceedingJoinPoint pjp) throws Throwable{
ServletRequestAttributes sra = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
System.out.println("========================================== Start ==========================================");
if (!Objects.isNull(sra) && !Objects.isNull(sra.getRequest())){
HttpServletRequest request = sra.getRequest();
//打印URL 此处还可打印其他参数
System.out.println("URL "+request.getRequestURL());
}
//获取SQL
String sql = SqlUtils.getMybatisSql(pjp, sqlSessionFactory);
System.out.println("sql : "+sql);
System.out.println("========================================== end ==========================================");
Object proceed = pjp.proceed();
return proceed;
}
Aop+Mybatis拦截器实现获取Sql和打印日志
最新推荐文章于 2024-06-28 11:03:28 发布