<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    城市獵人

    在一網(wǎng)情深的日子里,誰(shuí)能說(shuō)得清是苦是甜,只知道確定了就義無(wú)反顧
    posts - 1, comments - 7, trackbacks - 0, articles - 89

    AOP之靜態(tài)代理和動(dòng)態(tài)代理

    Posted on 2009-08-02 11:31 sailor 閱讀(921) 評(píng)論(2)  編輯  收藏 所屬分類(lèi): spring
    一、靜態(tài)代理:
        靜態(tài)代理要求代理對(duì)象和被代理對(duì)象實(shí)現(xiàn)同一個(gè)對(duì)象。

    IUserService:
    package com.swjs.aop.serivce;

    import java.util.List;

    /**
     * 
    @author jason
     *
     
    */

    public interface IUserService {
        List getUserList();
    }


    被代理類(lèi)UserService:
    package com.swjs.aop.serivce;

    import java.util.List;

    /**
     * 
    @author jason
     *
     
    */

    public class UserService implements IUserService {

        
    public List getUserList() {
            System.out.println(
    "get Userlist");
            
    return null;
        }


    }

    代理類(lèi):
    package com.swjs.aop.serivce;

    import java.util.List;

    /**
     * 
    @author jason
     *
     
    */

    public class SecureProxy implements IUserService{

        
    private IUserService userService;

        
    public SecureProxy(IUserService userService) {
            
    super();
            
    this.userService = userService;
        }

        
        
    public List getUserList()
        
    {
            System.out.println(
    "身份檢查");
            userService.getUserList();
            System.out.println(
    "事務(wù)提交");
            
    return null;
        }

    }

    測(cè)試類(lèi):
    package com.swjs.aop.serivce;

    /**
     * 
    @author jason
     *
     
    */

    public class StaticProxyTest {

        
    /**
         * 
    @param args
         
    */

        
    public static void main(String[] args) {
            IUserService userService 
    = new UserService();
            SecureProxy proxy 
    = new SecureProxy(userService);
            proxy.getUserList();
        }

    }


    顯示結(jié)果:
    身份檢查
    get Userlist
    事務(wù)提交

    二:動(dòng)態(tài)代理
    接口
    public interface IUserService {

        
    public void getUserList(int start, int limit);
    }


    業(yè)務(wù)方法:
    public class UserService implements IUserService {

        
    public void getUserList(int start, int limit) {
            System.out.println(
    "start: " + start + " limit: " + limit );
            System.out.println(
    "get user List");
        }

    }

    處理器:
    public class SecureHandler implements InvocationHandler {

        
    private IUserService service;
        
        
        
    public SecureHandler(IUserService service) {
            
    super();
            
    this.service = service;
        }



        
    public Object invoke(Object proxy, Method method, Object[] arg)
                
    throws Throwable {
            System.out.println(
    "trac begin");
            System.out.println(arg.length);
            
    for(int i = 0; i <  arg.length; i++)
            
    {
                System.out.println(arg[i]);
            }

            method.invoke(service, arg);
            System.out.println(
    "trac end");
            
    return null;
        }


    }


    測(cè)試類(lèi):
    public class DynamicProxyTest {

        
    public static void main(String[] args)
        
    {
            IUserService service 
    = new UserService();
            SecureHandler handler 
    = new SecureHandler(service);
            IUserService serv 
    = (IUserService)Proxy.newProxyInstance(service.getClass().getClassLoader(), 
                            service.getClass().getInterfaces(), handler);
            serv.getUserList(
    0,10);
        }

    }

    顯示結(jié)果:
    trac begin
    2
    0
    10
    start: 
    0 limit: 10
    get user List
    trac end

    Feedback

    # re: AOP之靜態(tài)代理和動(dòng)態(tài)代理  回復(fù)  更多評(píng)論   

    2014-12-05 17:03 by AloneAli
    實(shí)質(zhì)就是裝飾者模式?

    # re: AOP之靜態(tài)代理和動(dòng)態(tài)代理  回復(fù)  更多評(píng)論   

    2014-12-05 17:11 by AloneAli
    @AloneAli不好意思,弄錯(cuò)了。代理模式是種模式。。。不是裝飾者模式。
    主站蜘蛛池模板: 高潮毛片无遮挡高清免费视频| 亚洲AV无码一区二区三区牛牛| 亚洲美女aⅴ久久久91| 亚洲毛片一级带毛片基地| 亚洲欧洲另类春色校园网站| 久青草视频97国内免费影视| 四虎国产精品成人免费久久 | 亚洲资源在线视频| 一本色道久久88—综合亚洲精品| 国产精品亚洲专区无码不卡| 国产裸体美女永久免费无遮挡| 最近免费中文字幕大全高清大全1| 大陆一级毛片免费视频观看i| AV在线亚洲男人的天堂| 亚洲美女激情视频| 在线播放亚洲精品| 无码午夜成人1000部免费视频| 毛片免费视频观看| 久久精品国产精品亚洲人人 | 处破女第一次亚洲18分钟| 在线看片免费人成视频久网下载 | www视频在线观看免费| 国产jizzjizz免费视频| 亚洲高清在线播放| 亚洲gay片在线gv网站| 久久精品乱子伦免费| 在线免费观看韩国a视频| 久久亚洲国产伦理| 看亚洲a级一级毛片| 久久一本岛在免费线观看2020| 日韩视频在线免费观看| 亚洲大片在线观看| 精品女同一区二区三区免费播放 | 免费又黄又爽的视频| 亚洲人成网址在线观看| 成人精品国产亚洲欧洲| 十九岁在线观看免费完整版电影| 国产人妖ts在线观看免费视频| 亚洲精品美女在线观看| 国产V片在线播放免费无码 | 精品国产免费人成电影在线观看 |