<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)

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 日韩毛片免费无码无毒视频观看| 人妻巨大乳hd免费看| a色毛片免费视频| 久久影院亚洲一区| xxxxx做受大片在线观看免费| 亚洲精品国产自在久久| 一级一片免费视频播放| 亚洲自偷自偷偷色无码中文| 国产日韩在线视频免费播放| 国产AV无码专区亚洲AV漫画| 日韩a级无码免费视频| 婷婷亚洲综合五月天小说| 24小时日本韩国高清免费| 亚洲网站在线免费观看| 亚洲精品视频免费在线观看| 亚洲一区电影在线观看| 成人爱做日本视频免费| 一级特黄aaa大片免费看| 亚洲精品无码久久久久去q | 国产视频精品免费视频| 亚洲精品国产精品乱码视色 | 波多野结衣免费在线| 最近新韩国日本免费观看| 亚洲国产美女在线观看| 在线播放高清国语自产拍免费| 国产精品亚洲一区二区三区| 国产精品亚洲综合一区| 亚欧在线精品免费观看一区| 亚洲最大无码中文字幕| va亚洲va日韩不卡在线观看| 免费观看成人久久网免费观看| 亚洲人妖女同在线播放| 四虎影院永久免费观看| 免费91最新地址永久入口| 最新亚洲精品国偷自产在线| 亚洲精品成人网久久久久久| h视频在线免费看| 日本高清不卡中文字幕免费 | 久久99国产亚洲高清观看首页| 国产四虎免费精品视频| 一级特黄a大片免费|