After returning advice to use @AfterReturing
It can get our method's return value
The method can be defined by returning the return value of the attribute, as a parameter
Rear notice substantially used as follows:
There follows the ApplicationContex.xml:
<?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:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!--开启aspectJ的注解开发,AspectJ的自动代理--> <aop:aspectj-autoproxy/> <!- <->the target class bean id="xiaomao" class="com.AspecJ.xiaomaoDao"></bean> <!--切面类--> <bean class="com.AspecJ.aspectj"/> </beans>
There follows the target class:
package com.AspecJ; public class xiaomaoDao { public void save(){ System.out.println("save xiaomao!"); } public void find(){ System.out.println("find xiaomao!"); } public String delete(){ System.out.println("delete xiaomao!"); return "xiaomao"; } public void update(){ System.out.println("update xiaomao!"); } }
In the aspect class is defined as follows:
package com.AspecJ; import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class aspectj { // @Before(value = "execution(* com.AspecJ.xiaomaoDao.*(..))") // public void before(){ // System.out.println("我是前置通知!"); // } @AfterReturning(value = "execution(* com.AspecJ.xiaomaoDao.delete())",returning = "element") // 使用returning来接受返回值 public void After(Object element){ System.out.println ("I removed the" + Element); // print out the return value } }
Finally, the return value is as follows
I notice is the front! xiaomao the Delete ! I deleted xiaomao I notice is the front! xiaomao the Find ! I was before advice! xiaomao the Save ! I notice is the front! xiaomao Update !