Spring Boot攔截器配置
阿新 • • 發佈:2019-01-27
1.before
2.環繞增強@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; } } }
@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; } }