- package edu.ytu.demo;
- public class BeanText{
- private int age;
- private String name;
- public BeanText(int age, String name) {
- super();
- this.age = age;
- this.name = name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
-
- }
- package edu.ytu.demo;
- import org.apache.commons.beanutils.BeanUtils;
- public class BeanUtilDemo {
- public static void main(String[] args)throws Exception {
- BeanText t=new BeanText(23,"java");
- BeanUtils.setProperty(t, "name", "zhangsan");
- BeanUtils.setProperty(t, "age", "22");
-
- System.out.println("age="+BeanUtils.getProperty(t, "age"));
- System.out.println("Name="+BeanUtils.getProperty(t, "name"));
- }
- }
复制代码 做了一点修改,将两个类分开放在两个文件中声明为public权限,按照你的做法BeanText是默认权限,BeanUtils框架根本无法访问你的Beantext类 |