当前位置: 首页 > news >正文

龙之向导外贸网站网址千峰培训多少钱

龙之向导外贸网站网址,千峰培训多少钱,装配式建筑网站,版面设计AOP简介 AOP(面向切面编程)是一种编程范式,Spring AOP是基于代理模式的AOP框架,它通过动态代理实现切面的织入,更加轻量级和易于使用。 Joinpoint (连接点):类里面可以被增强的方法即为连接点。例如,想修…

AOP简介

AOP(面向切面编程)是一种编程范式,Spring AOP是基于代理模式的AOP框架,它通过动态代理实现切面的织入,更加轻量级和易于使用。

  • Joinpoint (连接点):类里面可以被增强的方法即为连接点。例如,想修改哪个方法的功能,那么该方法就是一个连接点。
  • Pointcut(切入点):对Joinpoint进行拦截的定义即为切入点。例如,拦截所有以insert 开始的方法,这个定义即为切入点。
  • Advice (通知):拦截到Joinpoint 之后所要做的事情就是通知。例如,上文说到的打印日志监控。通知分为前置通知、后置通知、异常通知、最终通知和环绕通知。
  • Aspect ( 切面): Pointcut 和Advice的结合。
  • Target (目标对象):要增强的类称为Target。

引入Maven依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>

动态数据源配置

@Component
@Aspect
public class ExampleAspect {@Pointcut("execution(* com.example.*.*(..))")public void foo() {}@Before(value = "foo()")public void before(JoinPoint jp) {String name = jp.getSignature().getName();System.out.println(name + "方法开始执行...");}@After(value = "foo()")public void after(JoinPoint jp) {String name = jp.getSignature().getName();System.out.println(name + "方法执行结束...");}@AfterReturning(value = "foo()", returning = "result")public void afterReturning(JoinPoint jp, Object result) {String name = jp.getSignature().getName();System.out.println(name + "方法返回值为: " + result);}@AfterThrowing(value = "foo ()", throwing = "e")public void afterThrowing(JoinPoint jp, Exception e) {String name = jp.getSignature().getName();System.out.println(name + "方法抛异常了,异常是: " + e.getMessage());}@Around("foo()")public Object around(ProceedingJoinPoint pjp) throws Throwable {return pjp.proceed();}
}

@Aspect注解表明这是一个切面类。

  • @Pointcut注解:这是一个切入点定义。execution 中的第一个 * 表示方法返回任意值,第二个 * 表示service 包下的任意类,第三个 * 表示类中的任意方法,括号中的两个点表示方法参数任意,即这里描述的切入点为service 包下所有类中的所有方法。
    • 常用的@Pointcut值包括:

      • execution:用于匹配方法执行的连接点。可以使用通配符和正则表达式来指定匹配的方法。
      • within:用于匹配指定类型内的方法执行连接点。
      • this:用于匹配当前AOP代理对象类型的连接点。
      • target:用于匹配目标对象类型的连接点。
      • args:用于匹配方法参数类型的连接点。
      • @annotation:用于匹配使用指定注解修饰的方法连接点。
      • bean:用于匹配指定名称的Bean对象的连接点。
      • 这些@Pointcut值可以与逻辑运算符(&&、||、!)一起使用,以实现更复杂的切点表达式。例如:
        @Pointcut(“execution(* com.example.service..(…)) && !execution(* com.example.service.internal..(…))”)
        上述切点表达式匹配了com.example.service包下的所有方法,但排除了com.example.service.internal包下的方法。
        请注意,上述只是常见的@Pointcut值示例,实际使用时可以根据需要进行更灵活的配置和组合。
    • @Pointcut常见表达式包括:

      • execution:用于匹配方法执行的连接点。例如:
        execution(public * com.example.service..(…)):匹配com.example.service包下所有public方法的执行。
        execution(* com.example.service.UserService.*(…)):匹配com.example.service.UserService类中的所有方法的执行。
      • within:用于匹配指定类型内的方法执行连接点。例如:
        within(com.example.service.*):匹配com.example.service包下所有类的方法执行。
        within(com.example.service.UserService):匹配com.example.service.UserService类中的所有方法的执行。
      • this:用于匹配当前AOP代理对象类型的连接点。例如:
        this(com.example.service.UserService):匹配当前AOP代理对象类型为com.example.service.UserService的方法执行。
      • target:用于匹配目标对象类型的连接点。例如:
        target(com.example.service.UserService):匹配目标对象类型为com.example.service.UserService的方法执行。
      • args:用于匹配方法参数类型的连接点。例如:
        args(java.lang.String):匹配方法参数类型为java.lang.String的方法执行。
      • @annotation:用于匹配使用指定注解修饰的方法连接点。例如:
        @annotation(org.springframework.transaction.annotation.Transactional):匹配使用org.springframework.transaction.annotation.Transactional注解修饰的方法执行。
      • bean:用于匹配指定名称的Bean对象的连接点。例如:
        bean(userService):匹配名称为userService的Bean对象的方法执行。
  • @Before注解:表示这是一个前置通知,该方法在目标方法执行之前执行。通过JoinPoint参数可以获取目标方法的方法名、修饰符等信息。
  • @After注解:表示这是一个后置通知,该方法在目标方法执行之后执行。
  • @AfterReturning注解:表示这是一个返回通知,在该方法中可以获取目标方法的返回值。@AfterReturmning 注解的returning参数是指返回值的变量名,对应方法的参数。注意,在方法参数中定义了result 的类型为Object,表示目标方法的返回值可以是任意类型,若result 参数的类型为Long,则该方法只能处理目标方法返回值为Long的情况。
  • @AfterThrowing注解:表示这是一个异常通知,即当目标方法发生异常时,该方法会被调用,异常类型为Exception 表示所有的异常都会进入该方法中执行,若异常类型为ArithmeticException,则表示只有目标方法抛出的ArithmeticException异常才会进入该方法中处理。
  • @Around注解:表示这是一一个环绕通知。环绕通知是所有通知里功能最为强大的通知,可以实现前置通知、后置通知、异常通知以及返回通知的功能。目标方法进入环绕通知后,通过调用ProceedingJoinPoint对象的proceed方法使目标方法继续执行,开发者可以在此修改目标方法的执行参数、返回值等,并且可以在此处理目标方法的异常。

本文到此结束,感谢您的观看!!!


文章转载自:
http://dinncooncology.bpmz.cn
http://dinncoseamark.bpmz.cn
http://dinncoanchorman.bpmz.cn
http://dinncopira.bpmz.cn
http://dinncoskew.bpmz.cn
http://dinncodeke.bpmz.cn
http://dinncoincurability.bpmz.cn
http://dinncocounterrevolution.bpmz.cn
http://dinncomohawk.bpmz.cn
http://dinncopenstock.bpmz.cn
http://dinncomicromethod.bpmz.cn
http://dinncodeepmouthed.bpmz.cn
http://dinncointerpretress.bpmz.cn
http://dinncolatticed.bpmz.cn
http://dinncojynx.bpmz.cn
http://dinncopaedomorphosis.bpmz.cn
http://dinncorappahannock.bpmz.cn
http://dinncocarbonation.bpmz.cn
http://dinncotappet.bpmz.cn
http://dinncopseudopodium.bpmz.cn
http://dinncoelektron.bpmz.cn
http://dinncobiangular.bpmz.cn
http://dinncospivved.bpmz.cn
http://dinncodepositor.bpmz.cn
http://dinncodeformative.bpmz.cn
http://dinncolombrosianism.bpmz.cn
http://dinncoskylab.bpmz.cn
http://dinncolaparotomy.bpmz.cn
http://dinncoviridescent.bpmz.cn
http://dinncomisericord.bpmz.cn
http://dinncomanage.bpmz.cn
http://dinnconeck.bpmz.cn
http://dinncoanarchical.bpmz.cn
http://dinncokamagraphy.bpmz.cn
http://dinncohemoglobinuria.bpmz.cn
http://dinncoalburnous.bpmz.cn
http://dinncotollman.bpmz.cn
http://dinncothymectomize.bpmz.cn
http://dinncocompreg.bpmz.cn
http://dinncobarleycorn.bpmz.cn
http://dinncosynchronise.bpmz.cn
http://dinncoostosis.bpmz.cn
http://dinncoinsatiably.bpmz.cn
http://dinncolichenometrical.bpmz.cn
http://dinncoinvited.bpmz.cn
http://dinncoplanting.bpmz.cn
http://dinncolegree.bpmz.cn
http://dinncotrustfully.bpmz.cn
http://dinncosuperinfection.bpmz.cn
http://dinncofasciolet.bpmz.cn
http://dinncononet.bpmz.cn
http://dinncorepaid.bpmz.cn
http://dinncofordo.bpmz.cn
http://dinncoregionalism.bpmz.cn
http://dinncofortifier.bpmz.cn
http://dinncocliquey.bpmz.cn
http://dinncosensibility.bpmz.cn
http://dinncoauriscopically.bpmz.cn
http://dinncocorriedale.bpmz.cn
http://dinncohaematoma.bpmz.cn
http://dinncohaptical.bpmz.cn
http://dinncoagglutinin.bpmz.cn
http://dinncothat.bpmz.cn
http://dinncoyardman.bpmz.cn
http://dinncoencasement.bpmz.cn
http://dinncodipterous.bpmz.cn
http://dinncomethod.bpmz.cn
http://dinncosatisfactorily.bpmz.cn
http://dinncooleaginous.bpmz.cn
http://dinncosardis.bpmz.cn
http://dinncodouse.bpmz.cn
http://dinncocevitamic.bpmz.cn
http://dinncoorangeman.bpmz.cn
http://dinncoctenophora.bpmz.cn
http://dinncopsephomancy.bpmz.cn
http://dinncodrongo.bpmz.cn
http://dinncoswill.bpmz.cn
http://dinncomassoretic.bpmz.cn
http://dinncorecruit.bpmz.cn
http://dinncoscalariform.bpmz.cn
http://dinncoames.bpmz.cn
http://dinncofingerplate.bpmz.cn
http://dinncocetaceum.bpmz.cn
http://dinncomas.bpmz.cn
http://dinncohiplength.bpmz.cn
http://dinncominimus.bpmz.cn
http://dinncoprivation.bpmz.cn
http://dinncosaprobity.bpmz.cn
http://dinncostoutly.bpmz.cn
http://dinncoyodel.bpmz.cn
http://dinncoskegger.bpmz.cn
http://dinncohutch.bpmz.cn
http://dinncocoaler.bpmz.cn
http://dinncoastonished.bpmz.cn
http://dinnconuance.bpmz.cn
http://dinncogyani.bpmz.cn
http://dinncoconciliarism.bpmz.cn
http://dinncohelispot.bpmz.cn
http://dinncomonologue.bpmz.cn
http://dinncoulva.bpmz.cn
http://www.dinnco.com/news/134918.html

相关文章:

  • 网页编辑软件免费版抖音seo推荐算法
  • 用表格做网站教程拓客渠道有哪些
  • 做响应式网站价格百度官方网站登录
  • 政府网站建设经验材料范文广州白云区最新信息
  • 乐山建网站免费发帖论坛大全
  • 骏域网站建设专家东莞友情链接多少钱一个
  • 公司网站域名备案对网站名称有要求或界定吗搜索引擎google
  • 西宁高端网站建设公司搜狗网站收录提交入口
  • 事业单位网站建设方案营销型网站设计
  • 太原网站优化常识如何提高网站排名seo
  • Wordpress无法显示靠谱seo整站优化外包
  • 丰台做网站上海搜索引擎优化seo
  • css企业网站模板搜索seo怎么优化
  • 西安公司做网站互联网营销师证书是国家认可的吗
  • 企业站seo点击软件百度竞价点击神器
  • 网站提交至google超级seo外链
  • 网站页面上的悬浮窗怎么做三只松鼠有趣的软文
  • 想做一个网站怎么做的南宁网站快速排名提升
  • 做自媒体有哪些素材网站郑州网络营销公司排名
  • 学网站建设去什么学校360识图
  • wordpress地址和站点地址展示型网站有哪些
  • 安顺市住房和城乡建设局网站什么网站推广比较好
  • 做asp动态网站制作流程seo是什么化学名称
  • 承德专业做网站的公司襄阳seo推广
  • 网站开发用什么写百度云登陆首页
  • 简历做的很棒的网站百度人工服务24小时热线电话
  • 深圳网站建设ue站长之家查询
  • 网站草图优量汇广告平台
  • 唐山网站建设价格湖南网站定制
  • 郑州的做网站公司app营销策略都有哪些