-
1…commons-beanutils
1.1提到内省,不能不提commons-beanutils这个工具。它底层了内省,对内省进行了大量的简化! 使用beanutils需要的jar包: commons-beanutils.jar; commons-logging.jar; 1.2设置JavaBean属性 User user = new User(); BeanUtils.setProperty(user, "username", "admin"); BeanUtils.setProperty(user, "password", "admin123"); System.out.println(user); 1.3获取JavaBean属性 User user = new User("admin", "admin123"); String username = BeanUtils.getProperty(user, "username"); String password = BeanUtils.getProperty(user, "password"); System.out.println("username=" + username + ", password=" + password); 1.4 封装Map数据到JavaBean对象中 Map<String,String> map = new HashMap<String,String>(); map.put("username", "admin"); map.put("password", "admin123"); User user = new User(); BeanUtils.populate(user, map); System.out.println(user);
常见 _ jar
最新推荐文章于 2024-10-31 15:56:11 发布