JoinPoint参数介绍接⼝:
package com.jzq.spring;
public interface UrManager {
public void addUr(String urname,String password);
public void deleteUr(int id);
public void modifyUr(int id,String urname,String password);
public String findUrById(int id);
}
实现类:
package com.jzq.spring;
public class UrManagerImpl implements UrManager {
@Override
public void addUr(String urname, String password) {
System.out.println("------UrManagerImpl.addUr()-----");
}
@Override
public void deleteUr(int id) {
System.out.println("--------UrManagerImpl.deleteUr()-------");
漫画照片男生帅气}
风和日丽的日子
@Override
public String findUrById(int id) {
System.out.println("--------UrManagerImpl.findUr()----------");
return null;
}
学会合作@Override
public void modifyUr(int id, String urname, String password) {
第二个字和第四个字是反义词的成语
System.out.println("--------deleteUr()-------");
}
}
切⼊⾯:
package com.jzq.spring;
涂眼霜的正确手法public class SecurityHandler {
private void checkSecurity()
{
System.out.println("---------checkSecurity()------------");
}
}
配置:
<bean id="curityHandler" class="com.jzq.spring.SecurityHandler"/>
<bean id="urManager" class="com.jzq.spring.UrManagerImpl"/>
<!-- aop的配置 -->
<aop:config>
<!-- 定义切⾯ -->
<aop:aspect id="curity" ref="curityHandler">
桂林游玩<!-- 定义切⾯中的pointcut -->
<aop:pointcut id="allAddMethod" expression="execution(* add*(..))"/>
<!-- 指定advice及应⽤到哪个pointcut -->
<aop:before method="checkSecurity" point-ref="allAddMethod"/>
</aop:aspect>
</aop:config>
</beans>
客户端:
package com.jzq.spring;
import org.springframework.beans.factory.BeanFactory;
import t.support.ClassPathXmlApplicationContext;
public class Client {
public static void main(String args[])
{
BeanFactory factory=new ClassPathXmlApplicationContext("l");
//注⼊UrManager的时候发现类中存在切⾯中声明的⽅法,故会⽣成⼀个动态代理类幼儿教师学习笔记
UrManager urManager=(Bean("urManager");
//当调⽤该⽅法的时候会根据spring配置来调⽤⽅法
urManager.addUr("张三", "123");
}
}
当urManager.addUr()根据配置执⾏了织⼊⽅法,如果此时想得到addUr⽅法中的参数,那么在切⼊⾯中的⽅法模块中添加参数JoinPoint
package com.jzq.spring;
import org.aspectj.lang.JoinPoint;
public class SecurityHandler {
private void checkSecurity(JoinPoint joinPoint)
{
Object[] Args();
for(int i=0;i<args.length;i++)
{
System.out.println(args[i]);
}
//得到⽅法名
System.out.Signature().getName());
System.out.println("---------checkSecurity()------------");
}
}
jdk只能对实现了接⼝的类⽣成动态代理
>惊破霓裳羽衣曲