斷點

          每天進步一點點!
          posts - 174, comments - 56, trackbacks - 0, articles - 21

          MethodUtils

          Posted on 2010-05-30 10:01 斷點 閱讀(437) 評論(0)  編輯  收藏 所屬分類: Apache

          MethodUtils的簡單用法。

          package com.ztf;

          import java.util.Map;

          import org.apache.commons.beanutils.MethodUtils;
          import org.apache.commons.beanutils.PropertyUtils;

          public class TestMethodUtils {  
                  
          public static void main(String[] args) throws Exception{  
                        
                      Entity entity 
          = new Entity();  
                      entity.setId(
          1) ;
                      entity.setName(
          "斷點");
                      
                     
          // 通過MethodUtils的invokeMethod方法,執(zhí)行指定的entity中的方法(無參的情況)
                      MethodUtils.invokeMethod(entity, "sayHello"null);  
                        
                      
          // 通過MethodUtils的invokeMethod方法,執(zhí)行指定的entity中的方法(1參的情況)
                      MethodUtils.invokeMethod(entity, "sayHello""斷點");  
                        
                      
          // 通過MethodUtils的invokeMethod方法,執(zhí)行指定的entity中的方法(多參的情況)
                      Object[] params = new Object[]{new Integer(10),new Integer(12)};  
                      MethodUtils.invokeMethod(entity, 
          "sayHello", params);  
                  }
            
          }
            

          實體:
          package com.ztf;

          public class Entity {
              
          private Integer id;
              
          private String name;
              
              
          public void sayHello(){
                  System.out.println(
          "sayHello()---> 無參");
              }

              
              
          public void sayHello(String s){
                  System.out.println(
          "sayHello()---> 有1個參數(shù)" );
              }

              
              
          public void sayHello(Integer a,Integer b){
                  System.out.println(
          "sayHello()---> 有2個參數(shù)");
              }

            
              
          public String getName() {
                  
          return name;
              }

              
          public void setName(String name) {
                  
          this.name = name;
              }

              
          public Integer getId() {
                  
          return id;
              }

              
          public void setId(Integer id) {
                  
          this.id = id;
              }

          }


          輸出:
          sayHello()---> 無參
          sayHello()---> 有1個參數(shù)
          sayHello()---> 有2個參數(shù)

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 通辽市| 深圳市| 墨脱县| 泾阳县| 平舆县| 庆元县| 六盘水市| 宝山区| 广宁县| 平湖市| 蒙阴县| 延边| 镇江市| 沂南县| 阳谷县| 新密市| 拜泉县| 高阳县| 镇远县| 南陵县| 昌图县| 外汇| 黄平县| 临澧县| 南康市| 德令哈市| 闻喜县| 白水县| 合肥市| 天祝| 浠水县| 宝应县| 汤阴县| 乡城县| 翁牛特旗| 丰都县| 东兴市| 格尔木市| 法库县| 海盐县| 龙游县|