public class BeanUtilsTest { /** * Java 类的属性: * 1、在JavaEE中,Java类的属性通过getter,setter来定义: get,set方法,去除 * get,set后,后字母小写即为J啊哪类的属性 * 2、而以前的那个属性,即成员变量,称之为字段 * 3、而操作java类的属性有一个工具包:beanutils * 1)setProperty() * 2)getProperty() * 搭建环境:需要同时加入:commons-beanutils-1.8.0.jar 和commons-logging-1.2.jar * * @throws Exception * @throws */ @Test public void testsetProperty() throws Exception { Object object = new Student(); System.out.println(object); BeanUtils.setProperty(object, "iDCard", "2112112119909"); System.out.println(object); } @Test public void testgetProperty() throws Exception { Object object = new Student(); System.out.println(object); BeanUtils.setProperty(object, "iDCard", "2112112119909"); System.out.println(object); Object obj = BeanUtils.getProperty(object, "iDCard"); System.out.println(obj); } }
转 : https://blog.csdn.net/YL1214012127/article/details/48350051
参: https://blog.csdn.net/wzc1991520/article/details/80176679