<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 閱讀(132) 評論(0)  編輯  收藏


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


    網站導航:
     

    My Links

    News

    留言簿(18)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 无码欧精品亚洲日韩一区| 性感美女视频免费网站午夜| 国产日韩AV免费无码一区二区三区| 久久亚洲中文无码咪咪爱| 亚洲一卡一卡二新区无人区| 亚洲一级毛片免费看| 亚洲性一级理论片在线观看| 久久精品国产亚洲av麻豆色欲| 在线观看亚洲一区二区| 亚洲视频在线观看| 中文字幕亚洲免费无线观看日本 | 99久久免费国产精精品| 皇色在线免费视频| 成人一区二区免费视频| 曰批全过程免费视频在线观看无码 | 大香人蕉免费视频75| 在线观看无码的免费网站| 性色av免费观看| 国产精品黄页在线播放免费| 亚洲 自拍 另类小说综合图区| 亚洲国产91精品无码专区| 中国亚洲女人69内射少妇| 亚洲国产三级在线观看| 亚洲另类激情综合偷自拍| 久久丫精品国产亚洲av不卡| 91亚洲视频在线观看| 亚洲人成网亚洲欧洲无码| 国产精品亚洲va在线观看| 九九免费精品视频在这里| 中文字幕成人免费高清在线视频| 在线观看免费无码专区| 亚洲一级免费视频| 女人张开腿给人桶免费视频 | 99xxoo视频在线永久免费观看| 亚洲一区免费在线观看| 性感美女视频在线观看免费精品| 亚洲人成无码网WWW| 亚洲av激情无码专区在线播放| 亚洲同性男gay网站在线观看| 亚洲AV无码专区亚洲AV桃| 久99久无码精品视频免费播放|