学做网站能赚钱吗搭建网站的过程
学做网站能赚钱吗,搭建网站的过程,o2o网站建设信息,网站方案建设书怎么写spring aop 的五种通知类型前置通知 Before advice#xff1a;在连接点前面执行#xff0c;前置通知不会影响连接点的执行#xff0c;除非此处抛出异常后置通知 After returning advice#xff1a;在连接点正常执行完成后执行#xff0c;如果连接点抛出异常#xff0c;则…spring aop 的五种通知类型前置通知Before advice在连接点前面执行前置通知不会影响连接点的执行除非此处抛出异常后置通知After returning advice在连接点正常执行完成后执行如果连接点抛出异常则不会执行异常通知After throwing advice在连接点抛出异常后执行最终通知After (finally) advice在连接点执行完成后执行不管是正常执行完成还是抛出异常都会执行返回通知中的内容环绕通知Around advice环绕通知围绕在连接点前后能在方法调用前后自定义一些操作还需要负责决定是继续处理join point(调用ProceedingJoinPoint的proceed方法)还是中断执行五大通知类型中环绕通知功能最为强大因为环绕通知可以控制目标方法是否执行。如果需要记录异常信息使用异常通知。其他通知只能做记录工作不能做处理所以执行顺序其实对整个程序影响不大没有必要太深究。spring aop 通知类型使用添加 Aspect 切面类package com.example.demo.module.aspect; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; Component Aspect public class AdviceTest { // 配置织入点 Pointcut(execution(public * com.example.demo.module.aspect.Test.*(..))) public void test(){ } Before(test()) public void doBefore(JoinPoint joinPoint){ System.out.println(joinPoint.getSignature().getName() 执行前置通知---); } AfterReturning(test()) public void doAfterSuccess(JoinPoint joinPoint){ System.out.println(joinPoint.getSignature().getName() 执行返回通知---); } AfterThrowing(test()) public void doAfterError(JoinPoint joinPoint){ System.out.println(joinPoint.getSignature().getName() 执行异常通知---); } Around(value test(), argNames pjp) public Object doAround(ProceedingJoinPoint pjp) { Object[] args pjp.getArgs(); Object result; try { // Before System.out.println(pjp.getSignature().getName() 环绕前置通知---); result pjp.proceed(args); // AfterReturning System.out.println(pjp.getSignature().getName() 环绕返回通知---); }catch (Throwable e){ // AfterThrowing System.out.println(pjp.getSignature().getName() 环绕异常通知---); throw new RuntimeException(e); }finally { // After System.out.println(pjp.getSignature().getName() 环绕最终通知---); } return result; } After(test()) public void doAfter(JoinPoint joinPoint){ System.out.println(joinPoint.getSignature().getName() 执行最终通知---); } }添加测试方法package com.example.demo.module.aspect; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; RequestMapping(test) RestController public class Test { GetMapping(testMethod) public void testMethod(){ System.out.println(方法执行---); } }运行结果测试异常通知修改测试方法package com.example.demo.module.aspect; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; RequestMapping(test) RestController public class Test { GetMapping(testMethod) public void testMethod(){ int i 1/0; System.out.println(方法执行---); } }运行结果通知执行顺序Spring 版本不一样通知执行顺序可能也会存在差异Before、After、AfterReturning、AfterThrowing执行顺序Spring 4.0正常情况Before - 目标方法 - After - AfterReturning异常情况Before - 目标方法 - After - AfterThrowingSpring 5.28正常情况Before - 目标方法 - AfterReturning - After异常情况Before - 目标方法 - AfterThrowing - AfterAround的执行顺序Spring 4.0正常情况环绕前置 - 目标方法执行 - 环绕返回 - 环绕最终异常情况环绕前置 - 目标方法执行 - 环绕异常 - 环绕最终Spring 5.28正常情况环绕前置 - 目标方法执行 - 环绕返回 - 环绕最终异常情况环绕前置 - 目标方法执行 - 环绕异常 - 环绕最终五大通知执行顺序Spring 4.0正常情况环绕前置 - Before - 目标方法执行 - 环绕返回 - 环绕最终 - After - AfterReturning异常情况环绕前置 - Before - 目标方法执行 - 环绕异常 - 环绕最终 - After - AfterThrowingSpring 5.28正常情况环绕前置 - Before - 目标方法执行 - AfterReturning - After - 环绕返回 - 环绕最终异常情况环绕前置 - Before - 目标方法执行 - AfterThrowing - After - 环绕异常 - 环绕最终