标题: JavaBean中的BeanUtils.getProperty(p, "x");怎么用 [打印本页] 作者: RubinYim 时间: 2014-7-7 10:11 标题: JavaBean中的BeanUtils.getProperty(p, "x");怎么用 import org.apache.commons.beanutils.BeanUtils;public class Test { /** * @param args */ public static void main(String[] args)throws Exception { // TODO Auto-generated method stub Person p = new Person(1, 3); //该怎么用? BeanUtils.setProperty(p, "x", 100); //该怎么用? System.out.println(BeanUtils.getProperty(p, "x")); }}class Person{ private int x; private int y; public Person(int x,int y) { this.x = x; this.y = y; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } } 作者: RubinYim 时间: 2014-7-7 10:23
import org.apache.commons.beanutils.BeanUtils;
public class Test {
/**
* @param args
*/
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
Person p = new Person(1, 3);
//出错,Cannot set x 该怎么用?
BeanUtils.setProperty(p, "x", 100);
//该怎么用?
System.out.println(BeanUtils.getProperty(p, "x"));
}
}
class Person
{
private int x;
private int y;
public Person(int x,int y)
{
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}