黑马程序员技术交流社区

标题: BeanUtils工具包获取属性值 [打印本页]

作者: 蒋淑静    时间: 2014-1-6 23:13
标题: BeanUtils工具包获取属性值
这样使用BeanUtils工具包获取属性的值对不?
  1. public class ReflectPoint {
  2.         private int x;
  3.         public int y;
  4.        
  5.         ReflectPoint(int x,int y){
  6.                 this.x=x;
  7.                 this.y=y;
  8.         }
  9.         public int getX() {
  10.                 return x;
  11.         }
  12.         public void setX(int x) {
  13.                 this.x = x;
  14.         }

  15. }
复制代码

  1. import org.apache.commons.beanutils.BeanUtils;
  2. public class JavaBeanTest {
  3.         public static void main(String[] args) throws Exception{
  4.                 ReflectPoint pt1 = new ReflectPoint(3,5);
  5.                 System.out.println(BeanUtils.getProperty(pt1,"x"));
  6.         }
  7. }
复制代码

作者: 蒋淑静    时间: 2014-1-7 18:31
没有人能帮忙看一下吗?
作者: FFF    时间: 2014-1-8 08:28
        这个问题可能比较深入~我也不知道呢~只要结果对就好啦、

作者: 蒋淑静    时间: 2014-1-8 14:59
我就是试了好像不能用,也不知道正确的使用方式是什么?,我再查查资料看吧,谢谢你
作者: 蒋淑静    时间: 2014-1-8 15:00
FFF 发表于 2014-1-8 08:28
这个问题可能比较深入~我也不知道呢~只要结果对就好啦、


我就是试了好像不能用,也不知道正确的使用方式是什么?,我再查查资料看吧,谢谢你




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2