标签:ati control style span ram frame home 异常 throwable
统一异常处理,aop
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; import java.util.HashMap; import java.util.Map; @Aspect @Component public class TestAop { /** * 定义切入点 */ @Pointcut("execution(* com.springboot_aop.controller.*.*(..))") public void homeWorkPointcut() { System.out.println(); } @Before("homeWorkPointcut()") public void test01() { System.out.println("执行前///////"); } @After("homeWorkPointcut()") public void test02() { System.out.println("执行后////"); } @Around("homeWorkPointcut()") public Object deAround(ProceedingJoinPoint joinPoint) throws Throwable { System.out.println("环绕前/////"); try { return joinPoint.proceed(); }catch (Throwable e){ Map<String, Object> data = new HashMap<>(); data.put("code","500"); data.put("msg",e.getMessage()); e.printStackTrace(); return data; } } }
标签:ati control style span ram frame home 异常 throwable
原文地址:https://www.cnblogs.com/qq376324789/p/12217080.html