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

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

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

    afunms

    My Software,My Dream—Forge a more perfect NMS product.

    new framework(4)--fetch request parameters value via reflect

    最討厭就是寫一大堆request.getParameter,新架構(gòu)中利用反射自動提取request中的參數(shù)值,
    然后把它們封閉成一個dto,真是太爽了。

     

        protected DtoInterface extractData(Class<? extends DtoInterface> clazz)
        
    {
            DtoInterface dto 
    = null;
            
    try
            
    {
                dto 
    = clazz.newInstance();
                Method[] methods 
    = clazz.getMethods();
                
    for(Method method:methods)
                
    {
                    
    if(!method.getName().startsWith("set")) continue;
                    
                    String paraValue 
    = getParaValueByMethodName(method.getName().substring(3));
                    
    if(paraValue==nullcontinue;
                    
                    Class
    <?>[] types = method.getParameterTypes();
                    
    if(types==null || types.length==0)
                        
    continue;
                    
    //                System.out.println("methodName=" + method.getName());
    //                System.out.println("para=" + method.getName().substring(3));
    //                System.out.println("paraValue=" + paraValue);
                    
                    
    if(types[0].getName().equals("int"))
                       method.invoke(dto,Integer.parseInt(paraValue));
                    
    else if(types[0].getName().equals("long"))    
                       method.invoke(dto,Long.parseLong(paraValue));
                    
    else if(types[0].getName().equals("double"))    
                        method.invoke(dto,Double.parseDouble(paraValue));
                    
    else if(types[0].getName().equals("float"))    
                         method.invoke(dto,Float.parseFloat(paraValue));
                    
    else
                       method.invoke(dto,paraValue); 
    //String    
                }

            }

            
    catch(Exception e)
            
    {
                SysLogger.error(
    "BaseAction.extractData()",e);    
            }

            
    return dto;
        }

        
        
    private String getParaValueByMethodName(String para)
        
    {
            String result 
    = null;
            
    for (Enumeration em = request.getParameterNames() ; em.hasMoreElements() ;)
            
    {
                String name 
    = (String)(em.nextElement());
                String temp 
    = name.replaceAll("_","");
                
    if(para.equalsIgnoreCase(temp))
                
    {
                    result 
    = request.getParameter(name);
                    
    break;
                }

            }

            
    return result;
        }

     

    posted on 2007-05-04 20:56 afunms 閱讀(129) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 成人无码区免费A∨直播| 亚洲无限乱码一二三四区| 美女的胸又黄又www网站免费| 妻子5免费完整高清电视| 亚洲精品视频观看| 18成禁人视频免费网站| 亚洲天堂电影在线观看| 日韩在线免费视频| 亚洲欧美日韩久久精品| 国产色爽女小说免费看| 成人国产网站v片免费观看| ZZIJZZIJ亚洲日本少妇JIZJIZ| 一级毛片免费毛片毛片| 久久久久噜噜噜亚洲熟女综合| 国产性生大片免费观看性 | 免费一级毛片在播放视频| 国产成人高清亚洲一区久久| 亚洲国产综合久久天堂| 中国一级毛片视频免费看| 中文字幕亚洲综合久久2| 日本阿v免费费视频完整版| 亚洲av永久无码精品网址| 亚洲精品偷拍视频免费观看 | 国产偷国产偷亚洲高清人| 亚洲精品人成无码中文毛片| 日本高清不卡aⅴ免费网站| 亚洲AV无码1区2区久久| 野花高清在线电影观看免费视频 | 亚洲卡一卡二卡乱码新区| 日本高清免费aaaaa大片视频| 国产免费区在线观看十分钟| 久久精品国产亚洲77777| 在线播放免费人成视频在线观看| 美女视频免费看一区二区| 亚洲va中文字幕无码久久| www.999精品视频观看免费| 福利片免费一区二区三区| 久久久久久亚洲精品中文字幕| 一二三四影视在线看片免费| 一级毛片免费毛片毛片| 亚洲午夜国产精品|