<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,新架構中利用反射自動提取request中的參數值,
    然后把它們封閉成一個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 閱讀(128) 評論(0)  編輯  收藏


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


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 亚洲熟妇av一区| 国产精品无码一二区免费| 亚洲av伊人久久综合密臀性色| 免费国产黄网站在线看| 免费一级e一片在线播放| 青娱乐在线视频免费观看| 免费国产怡红院在线观看| 黄网站色视频免费观看45分钟| 国产精品高清全国免费观看| 精品国产亚洲第一区二区三区| 四虎永久免费地址在线观看| 七次郎成人免费线路视频| 中文字幕一精品亚洲无线一区| 最近2019中文免费字幕在线观看| 亚洲AV无码码潮喷在线观看| 亚洲高清视频免费| 亚洲日韩AV一区二区三区中文 | 天天影视色香欲综合免费| 亚洲精品综合久久中文字幕 | 亚洲天堂电影在线观看| 日本三级2019在线观看免费| 亚洲中文字幕久久久一区| 免费午夜爽爽爽WWW视频十八禁 | 91精品国产免费| 亚洲最大无码中文字幕| 亚洲成年人啊啊aa在线观看| 日韩精品无码免费专区网站| 亚洲国产精品美女| 国产免费直播在线观看视频| 女同免费毛片在线播放| 亚洲国产高清视频在线观看| 波多野结衣视频在线免费观看 | 97公开免费视频| 亚洲av成人无码网站…| 亚洲色WWW成人永久网址| 在线观看永久免费| 黄色三级三级免费看| 91天堂素人精品系列全集亚洲| 日本免费网站在线观看| 国产婷婷成人久久Av免费高清 | 四虎国产精品免费视|