分享

org.apache.commons.beanutils.PropertyUtils 作用一例

 走墨 2014-07-25
package test;
import org.apache.commons.beanutils.PropertyUtils;
public class Test {
private int x;
private int y;
public int getX() {   //get ,set 方法不要忘记
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
Test(){
}
Test(int x,int y){
this.x=x;
this.y=y;
}
public static void main(String[] args) {
Test t=new Test(3,8);
try {
Object k= PropertyUtils.getProperty(t, "x");//理解其反射原理
System.out.println(k.toString());//打印 值:3
} catch (Exception e) {
e.printStackTrace();
}
}
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多