要导入beanutils.jar、logging.jar两个包
用来将获取的数据封装到javabean对应的属性中
public class TestPropertyUtils {
@Test
public void testPropertyUtils() throws Exception, InvocationTargetException, NoSuchMethodException{
Customer customer = new Customer();
PropertyUtils.setProperty(customer, "id", 5);
PropertyUtils.setProperty(customer, "name", "shawn");
PropertyUtils.setProperty(customer, "email", "shawn@163.com");
PropertyUtils.setProperty(customer, "birth", new Date(new java.util.Date().getTime()));
System.out.println(customer);
}
}
本文介绍如何利用Apache BeanUtils库简化JavaBean属性设置过程。通过示例代码演示了BeanUtils.setProperty方法的应用,该方法可以方便地为JavaBean对象设置各种类型的属性值。
502

被折叠的 条评论
为什么被折叠?



