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

    隨筆檔案

    相冊

    搜索

    最新評論

    閱讀排行榜

    主站蜘蛛池模板: 免费a级毛片无码a∨蜜芽试看 | 久久无码av亚洲精品色午夜 | 色爽黄1000部免费软件下载| 亚洲伊人久久大香线蕉苏妲己| 国产又大又长又粗又硬的免费视频| 最近免费视频中文字幕大全| selaoban在线视频免费精品| 亚洲国产成人精品无码区二本| 99久久亚洲精品无码毛片| 中文字幕精品亚洲无线码一区| 国产成人精品高清免费| 在线a级毛片免费视频| 18禁止看的免费污网站| 国产免费AV片在线观看| 中文字幕看片在线a免费| 九九久久精品国产免费看小说| 亚洲精品蜜夜内射| 亚洲一区二区三区91| 亚洲黄网站wwwwww| 亚洲av综合av一区| 亚洲色欲久久久综合网| 久久久久亚洲AV无码专区桃色| xvideos亚洲永久网址| 日本人护士免费xxxx视频| 成年女人免费视频播放77777| 可以免费看的卡一卡二| 91精品免费在线观看| 在线观看永久免费| 69国产精品视频免费| 亚洲一区二区三区免费视频| 99久久免费精品视频| 91视频免费网址| 91福利免费体验区观看区| 24小时日本韩国高清免费| 99久久99热精品免费观看国产| 91人成网站色www免费下载| 69影院毛片免费观看视频在线 | 亚洲国产成人久久精品影视| 亚洲AV日韩精品久久久久| 久久精品国产亚洲AV电影| 亚洲欧洲日产专区|