斷點

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

          MethodUtils

          Posted on 2010-05-30 10:01 斷點 閱讀(433) 評論(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方法,執行指定的entity中的方法(無參的情況)
                      MethodUtils.invokeMethod(entity, "sayHello"null);  
                        
                      
          // 通過MethodUtils的invokeMethod方法,執行指定的entity中的方法(1參的情況)
                      MethodUtils.invokeMethod(entity, "sayHello""斷點");  
                        
                      
          // 通過MethodUtils的invokeMethod方法,執行指定的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個參數" );
              }

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

            
              
          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個參數
          sayHello()---> 有2個參數

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


          網站導航:
           
          主站蜘蛛池模板: 佳木斯市| 奇台县| 封开县| 许昌市| 宁强县| 磐安县| 江阴市| 云和县| 海林市| 鸡西市| 河北省| 江川县| 合江县| 通河县| 顺平县| 金阳县| 阿拉善左旗| 万山特区| 镇江市| 疏勒县| 哈尔滨市| 云阳县| 西城区| 蕲春县| 崇仁县| 岑巩县| 隆林| 宣武区| 灵寿县| 额敏县| 勐海县| 文化| 清苑县| 建德市| 社会| 八宿县| 台山市| 闵行区| 读书| 云浮市| 建昌县|