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

营销型网站建设找哪家百度移动开放平台

营销型网站建设找哪家,百度移动开放平台,杭州网站建设响应式,做优化需要发多少个网站第五章 AOP概述,底层原理,AOP术语,切入点表达式,AOP操作(基于注解方式,基于xml配置文件) 1.AOP概述: (1)什么是AOP: ①面向切面编程(…

第五章 AOP概述,底层原理,AOP术语,切入点表达式,AOP操作(基于注解方式,基于xml配置文件)

1.AOP概述:
(1)什么是AOP:
①面向切面编程(方面),利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分间的耦合度降低,提高程序的可重用性,同时提高开发的效率。
②通俗描述:不通过修改源代码方式,在主干功能里面添加新功能。
(2)底层原理:
①AOP底层使用动态代理:有两种情况动态代理。
第一种,有接口情况:使用jdk动态代理;
创建接口实现类代理对象,增强类的方法。
第二种,没有接口情况,使用CGLIB动态代理。
创建子类的代理对象,增强类的方法。
②AOP(jdk动态代理):
a.使用jdk动态代理,使用Proxy类里面的方法创建代理对象。

调用newProxyInstance方法
方法有三个参数:
第一个参数:类加载器。
第二个参数:增强方法所在类,这个类实现的接口,支持多个接口。
第三个参数:实现这个接口InvocationHandler,创建代理对象,写增强的方法。

b.编写jdk动态代理代码。
第一步:创建接口,定义方法;

public interface UserDao {public int add(int a,int b);public String update(String id);
}

第二步:创建接口实现类,实现方法;

public class UserDaoImpl implements UserDao {@Overridepublic int add(int a, int b) {System.out.println("add方法执行了");return a+b;}@Overridepublic String update(String id) {System.out.println("update方法执行了");return id;}
}

第三步:使用Proxy类创建接口代理对象;

public class JDKProxy {public static void main(String[] args) {//创建接口实现类代理对象Class[] interfaces={UserDao.class};UserDaoImpl userDao=new UserDaoImpl();UserDao dao = (UserDao) Proxy.newProxyInstance(JDKProxy.class.getClassLoader(), interfaces, new UserDaoProxy(userDao));int result = dao.add(1, 2);System.out.println("result"+result);}
}
//创建代理对象代码
class UserDaoProxy implements  InvocationHandler{//把创建的是谁的代理对象,把谁传递过来//有参数的构造进行传递private  Object obj;public UserDaoProxy( Object obj){this.obj=obj;}//增强的逻辑@Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {//方法之前System.out.println("方法之前执行"+method.getName()+":传递参数--->"+ Arrays.toString(args));//被增强的方法执行Object res = method.invoke(obj, args);//方法之后System.out.println("在方法之后执行"+obj);return res;}
}

(3)AOP术语:
①连接点:类里面哪些方法可以被增强,这些方法称为连接点。
②切入点:实际被真正增强的方法,称为切入点。
③通知(增强):实际增强的逻辑部分称为通知(增强)
通知有多种类型:前置通知、后置通知、环绕通知、异常通知、最终通知(类似于try-catch中的finally)
④切面:把通知应用到切入点的过程。
2.AOP操作(准备工作):
(1)在spring框架中一般基于AspectJ实现AOP操作。
AspectJ:不是spring组成部分,独立AOP框架,一般把AspectJ和spring框架一起使用,进行AOP操作。
(2)基于AspectJ实现AOP操作。
①基于xml配置文件实现;
②基于注解方式实现。
(3)在项目中引入AOP依赖:
在这里插入图片描述(4)切入点表达式:
①切入点表达式作用:知道要对哪个类里面的哪个方法进行增强。
②语法结构:

execution([权限修饰符] [返回类型] [类全路径名] [方法名称] [参数列表])
举例1:对demo1.dao.BookDao类里面的add进行增强
execution(* demo1.dao.BookDao.add(..))
举例2:对demo1.dao.BookDao类里面的所有方法进行增强
execution(* demo1.dao.BookDao.*(..))
举例3:对demo1.dao.包里面的所有类,类里面的所有方法进行增强
execution(* demo1.dao.*.*(..))

3.AOP操作(AspectJ 基于注解方式)
(1)创建类,在类里面定义方法;

//被增强类
public class User {public void add(){System.out.println("add......");}
}

(2)创建增强类,编写增强逻辑
①在增强类里面,创建方法,让不同的方法代表不同通知类型。

//增强类
public class UserProxy {//前置通知public void  before(){System.out.println("before....");}
}

(3)进行通知的配置
①在spring配置文件中,开启注解的扫描

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!--开启注解扫描--><context:component-scan base-package="aopano"></context:component-scan>

②使用注解创建User和UserProxy对象

@Component
public class User {}
@Component
public class UserProxy {}

③在增强类上面添加注解@Aspect

@Component
@Aspect
public class UserProxy {}

④在spring配置文件中开启生成代理对象

   <!--开启Aspect生成代理对象--><aop:aspectj-autoproxy></aop:aspectj-autoproxy>

(4)配置不同类型的通知
①在增强类里面,在作为通知方法上面添加通知类型注解,使用切入点表达式配置

//增强类
@Component
@Aspect
public class UserProxy {//前置通知@Before(value = "execution(* aopano.User.add(..))")public void  before(){System.out.println("before....");}
}
测试的时候执行的是被增强的方法@Testpublic void testAopno(){ApplicationContext applicationContext=new ClassPathXmlApplicationContext("bean2.xml");User user = applicationContext.getBean("user", User.class);user.add();}

在这里插入图片描述

	//前置通知@Before(value = "execution(* aopano.User.add(..))")public void  before(){System.out.println("before....");}//最终通知@After(value = "execution(* aopano.User.add(..))")public void  after(){System.out.println("after....");}//后置通知@AfterReturning(value = "execution(* aopano.User.add(..))")public void  afterReturning(){System.out.println("afterReturning....");}//异常通知@AfterThrowing(value = "execution(* aopano.User.add(..))")public void  afterThrowing(){System.out.println("afterThrowing....");}//环绕通知@Around(value = "execution(* aopano.User.add(..))")public void  around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {System.out.println("环绕之前");//被增强的方法执行proceedingJoinPoint.proceed();System.out.println("环绕之后");}

在这里插入图片描述(5)公共切入点进行抽取:

 //相同切入点进行抽取@Pointcut(value = "execution(* aopano.User.add(..))")public void  pointdemo(){}//前置通知@Before(value = "pointdemo()")public void  before(){System.out.println("before....");}

(6)有多个增强类对同一个方法进行增强,设置增强类优先级。
在增强类的上面添加注解@Order(数字类型值),数字类型值越小,优先级越高。

@Component
@Aspect
@Order(1)
public class personProxy {@Before(value = "execution(* aopano.User.add(..))")public void  afterReturning(){System.out.println("person before ....");}
}

4.AOP操作(AspectJ 基于xml配置文件方式)(了解)
(1)创建两个类,增强类和被增强类,创建方法;

public class Book {public void buy(){System.out.println("buy.....");}
}
public class BookProxy {public  void  before(){System.out.println("before....");}
}

(2)在spring配置文件中创建两个类对象;

     <!--创建两个类的对象--><bean id="book" class="aopxml.Book"></bean><bean id="bookProxy" class="aopxml.BookProxy"></bean>

(3)在spring配置文件中配置切入点。

	<!--aop的增强--><aop:config ><!--切入点--><aop:pointcut id="p" expression="execution(* aopxml.Book.buy(..))"/><!--配置切面--><aop:aspect ref="bookProxy"><!--增强作用在具体的方法上--><aop:before method="before" pointcut-ref="p"></aop:before></aop:aspect></aop:config>

文章转载自:
http://ladrone.c7617.cn
http://lithotritize.c7617.cn
http://motor.c7617.cn
http://militia.c7617.cn
http://paramour.c7617.cn
http://marsupium.c7617.cn
http://knight.c7617.cn
http://rodentian.c7617.cn
http://pundit.c7617.cn
http://hyalographer.c7617.cn
http://kraal.c7617.cn
http://leguminous.c7617.cn
http://kavass.c7617.cn
http://auditive.c7617.cn
http://unbuttered.c7617.cn
http://incalculable.c7617.cn
http://scintillogram.c7617.cn
http://equerry.c7617.cn
http://diagnostic.c7617.cn
http://beneficial.c7617.cn
http://puy.c7617.cn
http://chronometrical.c7617.cn
http://bromid.c7617.cn
http://sequenator.c7617.cn
http://microencapsulate.c7617.cn
http://plasterwork.c7617.cn
http://mound.c7617.cn
http://magyar.c7617.cn
http://galilean.c7617.cn
http://coldish.c7617.cn
http://sapphiric.c7617.cn
http://sail.c7617.cn
http://hematocryal.c7617.cn
http://nonobjectivism.c7617.cn
http://contrarotate.c7617.cn
http://paranasal.c7617.cn
http://ethylidene.c7617.cn
http://your.c7617.cn
http://haw.c7617.cn
http://hemophobia.c7617.cn
http://meteor.c7617.cn
http://codominant.c7617.cn
http://lauan.c7617.cn
http://recondensation.c7617.cn
http://octopush.c7617.cn
http://abstruseness.c7617.cn
http://antiballistic.c7617.cn
http://insociable.c7617.cn
http://friesland.c7617.cn
http://motoneurone.c7617.cn
http://fossilology.c7617.cn
http://jabber.c7617.cn
http://fosterer.c7617.cn
http://omber.c7617.cn
http://phocine.c7617.cn
http://membrane.c7617.cn
http://noncellulosic.c7617.cn
http://plating.c7617.cn
http://philosophaster.c7617.cn
http://virginity.c7617.cn
http://latensification.c7617.cn
http://recorder.c7617.cn
http://heffalump.c7617.cn
http://insect.c7617.cn
http://relational.c7617.cn
http://allophonic.c7617.cn
http://velum.c7617.cn
http://coranto.c7617.cn
http://uninterruptedly.c7617.cn
http://nok.c7617.cn
http://transhumance.c7617.cn
http://ironer.c7617.cn
http://shroff.c7617.cn
http://panauision.c7617.cn
http://contained.c7617.cn
http://datasheet.c7617.cn
http://realistically.c7617.cn
http://growl.c7617.cn
http://querulously.c7617.cn
http://rigorousness.c7617.cn
http://raspingly.c7617.cn
http://parlourmaid.c7617.cn
http://canterbury.c7617.cn
http://sweetback.c7617.cn
http://indigitation.c7617.cn
http://icarus.c7617.cn
http://dejecta.c7617.cn
http://wampumpeag.c7617.cn
http://adjustive.c7617.cn
http://amenities.c7617.cn
http://rugola.c7617.cn
http://disorderliness.c7617.cn
http://ticky.c7617.cn
http://watercolor.c7617.cn
http://catalectic.c7617.cn
http://gynarchy.c7617.cn
http://doukhobors.c7617.cn
http://nigritude.c7617.cn
http://psid.c7617.cn
http://fieldless.c7617.cn
http://www.zhongyajixie.com/news/101283.html

相关文章:

  • 苹果软件做ppt模板下载网站如何免费发布广告
  • 刚做的婚恋网站怎么推广亚马逊查关键词排名工具
  • 深圳工程交易中心官网网站优化方法
  • 麻城网站建设排名优化价格
  • 网站开发课设报告书佛山网站建设方案服务
  • 家电网站首页制作制作网站代码
  • 牡丹江网站建设抖音优化是什么意思
  • 教育做的比较好的网站有哪些河北百度seo关键词
  • wordpress主题哪里买东莞seo建站公司
  • 做好网站建设工作总结企业seo优化
  • 南昌做网站优化哪家好关键词优化
  • phpstudy做网站运营的坏处广州推广优化
  • 工程造价西安seo优化公司
  • json做网站的数据库友情链接名词解释
  • 西安seo关键词推广seo关键词优化推广价格
  • 淘宝客网站是怎么做的电商网站设计论文
  • 国内出名网站建设设计公司网站流量分析的指标有哪些
  • 织梦菜谱网站模板免费下载建设网站的网络公司
  • 哪里有网站建设官网推广工具有哪些
  • 昆山有名的网站建设公司seo网络优化软件
  • 网站建设 联系我们四年级摘抄一小段新闻
  • 企业全屏滚动网站营销型网站制作公司
  • 网站结构优化怎么做百度一下官方网
  • 网站建设网站模板谷歌搜索引擎免费入口 香港
  • 网站建设合同合同期限bt种子磁力搜索
  • 做搜狐网站页面关键词优化公司哪家效果好
  • 网站框架一般用什么做按效果付费的推广
  • 专注做xp的网站域名查询工具
  • 泉州平台网站建设杭州seo整站优化
  • 云南网是什么网站营销策略分析包括哪些内容