1. 程式人生 > >Spring Boot攔截器配置

Spring Boot攔截器配置

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;
		}
	}