《获取javaBean所有属性及类型》由会员分享,可在线阅读,更多相关《获取javaBean所有属性及类型(4页珍藏版)》请在金锄头文库上搜索。
1、获得javaBean的所有属性及类型一、程序功能定义a) 获得javabean所有属性及类型b) 仅仅是获得,赋值还没想到怎么弄。二、目的a) 参考方法b) 目前还不知道有什么用。c) 本来想给javaBean 一次性赋值的,但是貌似吧得用反射才行,而反射挺费资源的, 那只好暂时搁一搁了。三、程序代码四、代码中公用到两个类a) getBea ns.java 与 pers on Bea n.java getBea ns.javaimportjava.bea ns.Bea nlnfo;importjava.bea ns.ln trospect ion Exceptio n;importjava.b
2、ea ns.ln trospector;import java.bea ns.PropertyDescriptor;public classgetBea ns * param args*/public static void main( Stri ng args) /TODO Auto-ge nerated method stubpers on Bea n pb=new pers on Bea n();PropertyDescriptorpr= getPropertyDescriptors(pb.getClass();=+pri.getPropertyType()for ( int i=1;i
3、pr.length;i+)System. out .println(pri.getName()+ );publicstaticPropertyDescriptorgetPropertyDescriptors(Classclazz) Bea nlnfo bea nlnfo =n ull ;try (clazz);bea nlnfo = In trospector.getBea nlnfo catch(In trospecti on Excepti on e) e.pri ntStackTrace();return bea nln fo.getPropertyDescriptors();pers
4、on Bea n.javapublic classperson Bean int id =0;Stri ngn ame = pheygirint she ngao =180; booleanmale =true ;public int getld() return id ;public void setld( int id) this . id = id;public String getName() retur n n ame;public void setName(Stri ng n ame) this . name = name;public int getShe ngao() retu
5、rnshengao ;public void setShe ngao( int she ngao) this . shengao = shengao;publicboolea nisMale() return male ;public void setMale( boolea n male) this . male = male;仅供参考,还不知道有没有用。When you are old and grey and full of sleep,And no ddi ng by the fire, take down this book,And slowly read, and dream of
6、 the soft lookYour eyes had once, and of their shadows deep;How many loved your mome nts of glad grace,And loved your beauty with love false or true,But one man loved the pilgrim soul in you,And loved the sorrows of your cha nging face;And bending dow n beside the glow ing bars,Murmur, a little sadl
7、y, how love fledAnd paced upon the mountains overheadAnd hid his face amid a crowd of stars.The furthest dista nee in the worldIs not betwee n life and deathBut whe n I sta nd in front of youYet you dont know thatI love you.The furthest dista nee in the worldIs not whe n I sta nd in front of youYet
8、you cant see my loveBut whe n un doubtedly knowing the love from bothYet cannot be together.The furthest dista nee in the worldIs not being apart while being in loveBut whe n I pla inly cannot resist the year ningYet prete nding you have n ever bee n in my heart.The furthest dista nee in the worldIs not struggli ng aga inst the tidesBut using on es in differe nt heartTo dig an un crossable riverFor the one who loves you.