美文网首页
aop和oop区别

aop和oop区别

作者: 蘋果_283e | 来源:发表于2017-04-25 16:32 被阅读0次

1、oop是java在面向对象编程

aop是面向切面编程,AOP主要应用于日志记录,性能统计,安全控制,事务处理等方面,它是为程序员解耦而生.

Spring五种类型的通知

1、前置通知[Before advice]:在连接点前面执行,前置通知不会影响连接点的执行,除非此处抛出异常。

3、正常返回通知[After returning advice]:在连接点正常执行完成后执行,如果连接点抛出异常,则不会执行。

3、异常返回通知[After throwing advice]:在连接点抛出异常后执行。

4、返回通知[After (finally) advice]:在连接点执行完成后执行,不管是正常执行完成,还是抛出异常,都会执行返回通知中的内容。

5、环绕通知[Around advice]:环绕通知围绕在连接点前后,比如一个方法调用的前后。这是最强大的通知类型,能在方法调用前后自定义一些操作。环绕通知还需要负责决定是继续处理join point(调用ProceedingJoinPoint的proceed方法)还是中断执行。

aop全注解开发

注解名 说明

@Controller 注解控制层组件,(如struts中的action)

@Service 注解业务层组件,service层组件

(@Service("service")
public class StudentServiceImpl implements StudentService {)

@Repository 注解数据访问层组件,DAO层组件

(@Repository("dao")
public class StudentDaoImpl implements StudentDao {)

@Component 泛指组件,当组件不好归类的时候,我们可以使用这个注解进行标注

@Autowired 默认是按照类型装配注入

@Resource 默认是按照名称来装配注入

(@Resource //或@Autowired

private StudentDaoImpl db;)

@Scope 注解用于指定scope作用域的(用在类上)

@Transactional 添加事务

service下面

注解配置AOP

1)使用注解@Aspect来定义一个切面,在切面中定义切入点(@Pointcut),通知类型(@Before、 @After 、@AfterReturning 、@AfterThrowing 、@Around )

2)开发需要被拦截的类

http://blog.csdn.net/sunlihuo/article/details/52701548

@Aspect

@Component("aop")// 泛指组件当组件不好归类的时候,我们可以使用这个注解进行标注(可以不写名字@Component)

public class AspInterceptor {

@Before("execution(* com.hw.service..*.add*(com.hw.entity.Student))")

public void before() {/*前置通知*/System.out.println("before....使用本程序先交9美金!!!");}

@After("execution(* com.hw.service.impl.*.add*(String))")

public void after() {/*正常返回通知*/System.out.println("after....程序使用正常9美金很值!!!");}

@AfterThrowing("execution(* com.hw.service.impl.*.*(..))")

public void afterthrowing() {/*异常返回通知*/System.out.println("throwing....程序使用有异常9美金上当了!!!");}

@AfterReturning("execution(* com.hw.service.impl.*.add*(..))")

public void afterfinally() {/*返回最终通知*/System.out.println("afterfinally....别想着程序了,9美金已交了!!!");}

@Around("execution(* com.hw.service.impl.*.update*(..))")

public void around(ProceedingJoinPoint pj) throws Throwable {// 环绕通知

System.out.println("环绕通知,要工作了");

pj.proceed();

System.out.println("环绕通知,要发工资了");

/*环绕通知:能在方法调用前后自定义一些操作。环绕通知还需要负 责决定是继续处理joinpoint(调用ProceedingJoinPoint的proceed方法)还是中断执行*/}}

3)将切面配置到xml中,也可以使用自动扫描bean方式

service dao:<context:component-scan base-package="com.hw" />

aspect :<aop:aspectj-autoproxy proxy-target-class="true"/>(面向切面自动代理)

相关文章

  • aop概念

    (1)oop与aop的区别: oop是面向对象编程,aop是面向切面编程或者面向方面编程.. (2)aop的用处和...

  • aop和oop区别

    1、oop是java在面向对象编程 aop是面向切面编程,AOP主要应用于日志记录,性能统计,安全控制,事务处理等...

  • AOP之AspectJ在Android中的应用

    1 前言 1.1 什么是AOP,与OOP的区别 OOP:即ObjectOriented Programming,面...

  • 【Android】AOP 面向切面编程(一) -- Aspect

    什么是AOP,与OOP的区别 OOP: (Object Oriented Programming) 面向对象的程序...

  • AOP/OOP区别

    区分 AOP、OOP在字面上虽然非常类似,但却是面向不同领域的两种设计思想。OOP(面向对象编程)针对业务处理过程...

  • AOP/OOP区别

    区分 AOP、OOP在字面上虽然非常类似,但却是面向不同领域的两种设计思想。OOP(面向对象编程)针对业务处理过程...

  • 大话AOP与Android的爱恨情仇

    1. AOP与OOP的区别 平时我接触多的就是OOP(Object Oriented Programming面向对...

  • Android中AOP的实际运用

    Android中AOP的实际运用 一、AOP简介 AOP即面向切面编程,区别于OOP(面向对象编程)的功能模块化,...

  • AOP技术

    来源Android开发中的AOP技术 前言 AOP的中文解释是面向切面编程,是一种编程范式。 OOP与AOP的区别...

  • Spring AOP篇

    一、什么是AOP? AOP(Aspect Oriented Programming)面向切面编程。 AOP和OOP...

网友评论

      本文标题:aop和oop区别

      本文链接:https://www.haomeiwen.com/subject/hfjvzttx.html