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

网站建设费可摊几年seo分析师

网站建设费可摊几年,seo分析师,如何设计自己的网站,如何做个盈利的网站文章目录前言一、Spring AOP基于注解的所有通知类型1、前置通知2、后置通知3、环绕通知4、最终通知5、异常通知二、Spring AOP基于注解之切面顺序三、Spring AOP基于注解之通用切点三、Spring AOP基于注解之连接点四、Spring AOP基于注解之全注解开发前言 通知类型包括&#x…

文章目录

  • 前言
  • 一、Spring AOP基于注解的所有通知类型
    • 1、前置通知
    • 2、后置通知
    • 3、环绕通知
    • 4、最终通知
    • 5、异常通知
  • 二、Spring AOP基于注解之切面顺序
  • 三、Spring AOP基于注解之通用切点
  • 三、Spring AOP基于注解之连接点
  • 四、Spring AOP基于注解之全注解开发


前言

通知类型包括:

  • 前置通知:@Before目标方法执行之前的通知
  • 后置通知:@AfterReturning目标方法执行之后的通知
  • 环绕通知:@Around目标方法之前添加通知,同时目标方法执行之后添加通知
  • 异常通知:@AfterThrowing发生异常之后执行的通知
  • 最终通知:@After放在finally语句块中的通知 -

一、Spring AOP基于注解的所有通知类型

1、前置通知

    //@Before(切点表达式 确定在哪里进行切入)标注的方法就是一个前置通知,在目标类的目标方法执行之前执行@Before("execution(* com.powernode.spring.service.UserService.* (..))")public void beforeAdvice(){System.out.println("前置通知");}

在这里插入图片描述

2、后置通知

    //后置通知@AfterReturning("execution(* com.powernode.spring.service.UserService.* (..))")public void afterReturningAdvice(){System.out.println("后置通知");}

在这里插入图片描述

3、环绕通知

    //环绕通知@Around("execution(* com.powernode.spring.service.UserService.* (..))")public void aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {//前面的代码System.out.println("前环绕");//执行目标joinPoint.proceed();//执行目标//后面的代码System.out.println("后环绕");}

注意:需要添加一个参数(ProceedingJoinPoint )去执行目标方法

在这里插入图片描述

4、最终通知

    //最终通知@After("execution(* com.powernode.spring.service.UserService.* (..))")public void afterAdvice(){System.out.println("最终通知");}

在这里插入图片描述

5、异常通知

目标方法中设计异常:

@Service("userservice") //将这个类纳入spring容器管理
public class UserService { //目标类public void login(){ //目标方法System.out.println("系统正在进行身份认证....");if(1==1){throw new RuntimeException("运行时异常");}}
}
    //异常通知@AfterThrowing("execution(* com.powernode.spring.service.UserService.* (..))")public void afterThrowing(){System.out.println("异常通知");}

在这里插入图片描述
发生异常后,后置通知以及后环绕都没有了

二、Spring AOP基于注解之切面顺序

再增加一个安全切面:

public class SecurityAspect { //安全切面//通知+切点@Before("execution(* com.powernode.spring.service.UserService.* (..))")public void beforeAdvice(){System.out.println("前置通知:安全……");}
}

那么安全切面和日志切面的执行顺序如何来排呢?
@Order注解
@Order(1)
@Order(2)
谁的数字越小优先级越高
在这里插入图片描述

三、Spring AOP基于注解之通用切点

切面表达式写了多次,怎么解决?

    @Pointcut("execution(* com.powernode.spring.service.UserService.* (..))")public void 通用切点(){//这个方法只是一个标记。方法名随意,方法体中也不需要写任何代码。}@Before("通用切点()")public void beforeAdvice(){System.out.println("前置通知");}

跨类的话:

    @Before("com.powernode.spring.service.LogAspect.通用切点()")public void beforeAdvice(){System.out.println("前置通知:安全……");}

在这里插入图片描述

三、Spring AOP基于注解之连接点

JoinPoint在Spring容器调用这个方法的时候自动传过来
我们可以用它来获取目标方法的签名

    @Before("通用切点()")public void beforeAdvice(JoinPoint joinPoint){System.out.println("前置通知");System.out.println("目标方法的方法名:"+joinPoint.getSignature().getName());}

在这里插入图片描述

四、Spring AOP基于注解之全注解开发

SpringConfig 代替spring.xml文件

@Configuration//代替spring.xml文件
@ComponentScan({"com.powernode.spring.service"}) //组件扫描
@EnableAspectJAutoProxy(proxyTargetClass = true) //开启aspectj的自动代理
public class SpringConfig {
}

测试程序:

    @Testpublic void testNoXml(){ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfig.class);UserService userservice = (UserService) ac.getBean("userservice");userservice.login();}

在这里插入图片描述


http://www.ds6.com.cn/news/62424.html

相关文章:

  • 凯里有哪些网站开发公司东莞网站推广软件
  • 自助网站电商平台推广方案
  • 怎么用手机创建网站关键词热度查询工具
  • 淘宝 客要推广网站怎么做百度网站app
  • 智能建站cms管理系统品牌营销策划有限公司
  • 厂房出租做推广什么网站好江苏网站seo
  • 电商网站的制作流程肇庆网站建设
  • 外贸网站怎么做seo优化电子商务网站建设案例
  • wordpress收费查看公司网站优化方案
  • java旅游网站开发项目浏览器打开
  • wordpress获取当前tag名称外汇seo公司
  • 前端做任务的网站谷歌seo实战教程
  • 做网站需要写那些xmind今天微博热搜前十名
  • 互动网站策划百度app推广
  • 代理做减肥网站西安百度推广代理商
  • 晋江做任务的网站南昌seo搜索排名
  • 深圳网站建设是什么杭州优化外包
  • 传统门户网站有哪些百度公司的业务范围
  • 初创企业网站建设流程词爱站的关键词
  • 划分切片来做网站sem工作原理
  • 南京网站建设公司 w营销组合策略
  • 微信扫码点餐小程序怎么做乐陵seo外包公司
  • 公司网站申请跨境电商平台有哪些
  • 自己建网站流程百度引擎搜索网址
  • 保定企业网站的建设百度怎么精准搜关键词
  • 南宁公司官网建站网站ip查询
  • 网站去掉index.html网络站点推广的方法
  • 网站开发 简单seo
  • 国内开源建站cms南昌网站开发公司
  • 西安建设商城类网站抖音seo教程