zoukankan      html  css  js  c++  java
  • Spring笔记--0907

    包含ioc和aop两大核心概念

    aop----事务管理

    spring框架运用的设计模式(查一下)

    ---------------------------------------
    Ioc(控制反转)和Di-----dependency injection(依赖注入)

    Ioc 被调用对象不是由调用对象生成(new),而是用spring容器(通过反射机制)生成

    ---------------------------------------
    先理解简单工厂(对象在工厂里new)---理解spring(对象在spring里new)
    ----------------------------------------
    代理模式:
    抽象角色,代理角色(对真实对象的一个封装,也重写了抽象类的方法,但没有具体实现),真实角色(最重要引

    用的对象)

    public Proxy extends Subject{
     realSubject real;
     @Override
     void request(){
      before();
      real=new RealSubject();//对真实对象的一个封装
      real.request();
      after();
     }
    }

    public class Test1{
     public static void main(String args[]){
      ProxySubject proxy=new ProxySubject();
      proxy.request();
     }
    }
    -----------------------------------------------------
    当真实对象事先不存在时,使用动态代理
    public  class DynamicSubject implements InvocationHandler{
     private Object obj;
     public DynamicSubject(Object obj){
     }
     public Object invoke(Proxy。。。。){
     method.invoke(sub,args);
     }
    }

    public class Test2{
     public static void main(String args[]){
      Real real=new Real();//真实角色
      InvocationHandler handler=new DynamicSubject(real);//动态代理处理器
      Class realClass=real.getClass();
      
      Real real1=(Real)Proxy.newProxyInstance(realClass.getClassLoader

    (),realClass.getInterfaces,handler);//调用代理模式的处理器,出现一个实例,1类加载器 2真是角色的接

    口3...
      real1.request();
      
     }
    }
    --------------------------------------------------------------------
    横切关注点,方面,连接点(程序执行过程中的一个点,如方法调用,字段访问。。),增强,切入点

    --------------------------------------------------------------------
    public class TransactionInterceptor implements MethodIntercptor{
     public Object invoke(){
      String methodName=arg0.getMethod().getName();
      if(methodName.startWith("save")||methodName.startWith("update")  ||methodName.startWith("delete")){
      System.out.println("DFJGKL//////");
      }
      arg0.proceed();
     }
    }

  • 相关阅读:
    多屏共享
    md5-linux_shell
    2017年会所得
    linux无线网络配置_转
    (转)台式机华硕主板双显卡切换,怎么舒服怎么来
    Apache FtpServer 实现文件的上传和下载
    (转载)Windows 上搭建Apache FtpServer
    Eclipse常用设置
    博客园文章样式修改
    黑马公社学习
  • 原文地址:https://www.cnblogs.com/ximencuixue/p/3307493.html
Copyright © 2011-2022 走看看