这样使用BeanUtils工具包获取属性的值对不?
- public class ReflectPoint {
- private int x;
- public int y;
-
- ReflectPoint(int x,int y){
- this.x=x;
- this.y=y;
- }
- public int getX() {
- return x;
- }
- public void setX(int x) {
- this.x = x;
- }
- }
复制代码
- import org.apache.commons.beanutils.BeanUtils;
- public class JavaBeanTest {
- public static void main(String[] args) throws Exception{
- ReflectPoint pt1 = new ReflectPoint(3,5);
- System.out.println(BeanUtils.getProperty(pt1,"x"));
- }
- }
复制代码 |