本帖最后由 黑马_位志国 于 2013-4-10 07:27 编辑
JavaBean文件:
import java.util.*;
public class Person {
private String name;
private int age;
private Date birthday;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}
}
实例:
import java.beans.*;
import java.lang.reflect.*;
import org.apache.commons.beanutils.BeanUtils;
public class PersonTest {
/**
* @param args
* @throws IntrospectionException
* @throws InvocationTargetException
* @throws IllegalArgumentException
* @throws IllegalAccessException
* @throws NoSuchMethodException
*/
public static void main(String[] args) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
// TODO Auto-generated method stub
Person p = new Person("ijunfu", 23);
BeanUtils.setProperty(p, "birthday.time", "111");
System.out.println(BeanUtils.getProperty(p, "birthday.time"));
}
}
为什么老是出现以下错误???
Exception in thread "main" java.lang.IllegalArgumentException: No bean specified
at org.apache.commons.beanutils.PropertyUtilsBean.getPropertyDescriptor(PropertyUtilsBean.java:883)
at org.apache.commons.beanutils.BeanUtilsBean.setProperty(BeanUtilsBean.java:935)
at org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:456)
at com.ijunfu.study.java.enhance.day01.PersonTest.main(PersonTest.java:35)
求教......
|