隨筆-204  評論-90  文章-8  trackbacks-0
          import java.lang.reflect.InvocationTargetException;
          import java.lang.reflect.Method;

          import org.apache.commons.lang.StringUtils;

          import com.sun.org.apache.commons.beanutils.PropertyUtils;


          /**
           * create_date : 2009-6-16
           
          */

          public class TestBean {

              
          private String uid;
              
          private String uname;
              
          private String sex;

              
          public String getUid() {
                  
          return uid;
              }


              
          public void setUid(String uid) {
                  
          this.uid = uid;
              }


              
          public String getUname() {
                  
          return uname;
              }


              
          public void setUname(String uname) {
                  
          this.uname = uname;
              }


              
          public String getSex() {
                  
          return sex;
              }


              
          public void setSex(String sex) {
                  
          this.sex = sex;
              }


              
          public String check() {
                  Method[] methods 
          = this.getClass().getMethods();
                  
          for (int i = 0; i < methods.length; i++{
                      Method method 
          = methods[i];
                      
          if (method.getName().startsWith("get")) {
                          
          try {
                              
          if(StringUtils.isBlank((String)method.invoke(this))){
                                  
          return method.getName().substring(3);
                              }

                          }
           catch (IllegalArgumentException e) {
                              e.printStackTrace();
                          }
           catch (IllegalAccessException e) {
                              e.printStackTrace();
                          }
           catch (InvocationTargetException e) {
                              e.printStackTrace();
                          }

                      }

                  }

                  
          return null;
              }

              
              
          public static void main(String[] args) {
                  TestBean tBean 
          = new TestBean();
                  tBean.setUid(
          "1234");
                  System.out.println(tBean.check());
              }

          }

          posted on 2009-06-16 15:35 一凡 閱讀(526) 評論(0)  編輯  收藏 所屬分類: JAVA 基礎
          主站蜘蛛池模板: 峨眉山市| 旺苍县| 正定县| 襄城县| 确山县| 无极县| 西林县| 贵德县| 乌拉特前旗| 巴彦淖尔市| 普格县| 华亭县| 望江县| 阳信县| 台江县| 六盘水市| 岳池县| 比如县| 乐都县| 晴隆县| 乳山市| 蚌埠市| 彭泽县| 栖霞市| 无为县| 潼关县| 阿城市| 乌恰县| 万载县| 万全县| 扶沟县| 基隆市| 吉隆县| 文成县| 修武县| 龙南县| 东源县| 石狮市| 偃师市| 寿光市| 襄樊市|