1.before
@Before("execution(* com.jrq.core.mapper..*Mapper.*(..))")
public void pageHandle(JoinPoint joinPoint) {
Object[] args = joinPoint.getArgs();
for (Object arg : args) {
if (arg != null && arg instanceof RowBounds) {
LOG.info("joinPoint: {}", joinPoint);
RowBounds rb = (RowBounds)arg;
PageHelper.startPage(rb.getOffset(), rb.getLimit());
break;
}
}
}
2.环绕增强
@Around("execution(* com.jrq.common.service..*Service.*(..))")
public Object aroundHandle(ProceedingJoinPoint joinPoint) {
LOG.info("joinPoint: {}", joinPoint);
try {
Object result = joinPoint.proceed();
return result;
} catch (Throwable t) {
if(t.getCause() instanceof PersistenceException ){
LOG.error("数据库连接出错 ~~ connection timeout");
}
LOG.error(t.getMessage(), t);
return 1;
}
}