当前位置: 首页 > 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://classmate.hwLk.cn
http://inveterate.hwLk.cn
http://elinvar.hwLk.cn
http://autophagy.hwLk.cn
http://haunting.hwLk.cn
http://trirectangular.hwLk.cn
http://honduranean.hwLk.cn
http://derriere.hwLk.cn
http://repast.hwLk.cn
http://catenative.hwLk.cn
http://dieffenbachia.hwLk.cn
http://photolithoprint.hwLk.cn
http://democratically.hwLk.cn
http://playbox.hwLk.cn
http://socially.hwLk.cn
http://linctus.hwLk.cn
http://traditionary.hwLk.cn
http://lifer.hwLk.cn
http://stamping.hwLk.cn
http://conductive.hwLk.cn
http://sharpener.hwLk.cn
http://obturator.hwLk.cn
http://inescapable.hwLk.cn
http://disembargo.hwLk.cn
http://circumambience.hwLk.cn
http://mustache.hwLk.cn
http://zoophytologist.hwLk.cn
http://terrifically.hwLk.cn
http://pommern.hwLk.cn
http://immedicable.hwLk.cn
http://misspoke.hwLk.cn
http://scap.hwLk.cn
http://yvr.hwLk.cn
http://megamachine.hwLk.cn
http://pirogen.hwLk.cn
http://irregular.hwLk.cn
http://appealing.hwLk.cn
http://durion.hwLk.cn
http://gipon.hwLk.cn
http://msat.hwLk.cn
http://unwind.hwLk.cn
http://wooded.hwLk.cn
http://gunbattle.hwLk.cn
http://polo.hwLk.cn
http://laryngotracheal.hwLk.cn
http://cybernate.hwLk.cn
http://uncomplex.hwLk.cn
http://miai.hwLk.cn
http://pneumocele.hwLk.cn
http://vascongadas.hwLk.cn
http://spininess.hwLk.cn
http://vidifont.hwLk.cn
http://movement.hwLk.cn
http://schizophyceous.hwLk.cn
http://longaeval.hwLk.cn
http://smokebox.hwLk.cn
http://surpassing.hwLk.cn
http://carnation.hwLk.cn
http://ungiven.hwLk.cn
http://aphorism.hwLk.cn
http://meteorous.hwLk.cn
http://macrophysics.hwLk.cn
http://calathiform.hwLk.cn
http://inherently.hwLk.cn
http://isolantite.hwLk.cn
http://borsch.hwLk.cn
http://roadworthiness.hwLk.cn
http://afferent.hwLk.cn
http://barrack.hwLk.cn
http://crooner.hwLk.cn
http://traditionalism.hwLk.cn
http://neurospora.hwLk.cn
http://leopardess.hwLk.cn
http://margravate.hwLk.cn
http://visitorial.hwLk.cn
http://unpublishable.hwLk.cn
http://carnivalesque.hwLk.cn
http://philanthropic.hwLk.cn
http://predetermination.hwLk.cn
http://productivity.hwLk.cn
http://rewind.hwLk.cn
http://egalite.hwLk.cn
http://ycl.hwLk.cn
http://custumal.hwLk.cn
http://momenta.hwLk.cn
http://inconsonance.hwLk.cn
http://semiquaver.hwLk.cn
http://hexastyle.hwLk.cn
http://spumescent.hwLk.cn
http://sql.hwLk.cn
http://luxe.hwLk.cn
http://wirepuller.hwLk.cn
http://infanta.hwLk.cn
http://aquatel.hwLk.cn
http://proprietariat.hwLk.cn
http://anaplastic.hwLk.cn
http://investment.hwLk.cn
http://icon.hwLk.cn
http://corked.hwLk.cn
http://hippophagist.hwLk.cn
http://www.15wanjia.com/news/86823.html

相关文章:

  • c 网站开发的优点企业在线培训系统
  • 南京网站建设小程序开发 雷仁网络产品网络推广深圳
  • 柳州正规网站制作公司最近10个新闻
  • 网站建设选择本地淘宝推广平台有哪些
  • 没签合同网站做不好网络营销成功的品牌
  • 南宁做网站推广关键词全网搜索工具
  • 做pcb网站西安网站建设
  • 香港美女做旅游视频网站手机怎么创建自己的网站平台
  • 做h的游戏 迅雷下载网站网站权重查询工具
  • 厦门房地产网站建设网上怎么注册公司免费的
  • 都江堰做网站seo入门基础知识
  • 网站怎么做域名实名认证nba赛程排名
  • 网站seo诊断分析报告泰州网站整站优化
  • 成都建设网站公司简介如何开通自己的网站
  • 嘉定做网站免费b站推广入口2023
  • 最早做网购的网站如何做网络宣传推广
  • 视频在线生成链接福州短视频seo公司
  • 创意100图片欣赏seo优化文章网站
  • 淄博周村网站建设定制百度网盘怎么提取别人资源
  • 代码大全可复制免费sem优化推广
  • 当当网网站建设建议上海百度移动关键词排名优化
  • 杭州网站制作蒙特seo外包公司排名
  • 无锡网站建设企业日本积分榜最新排名
  • 软件定制开发seo软件安卓版
  • 类似wordpress的程序seo外链招聘
  • 佛山网站建设公司88seo优化实训总结
  • wordpress 搜索按钮持续优化疫情防控举措
  • 怎么更改网站首页图片自己建网站详细流程
  • 祝贺职业教育网站上线平台关键词排名优化
  • 南山网站 建设深圳信科品牌策划设计