public class TestPropertyUtils {
public void test(){
//自己随便写两个类
Fffff ff = new Fffff();
ff.setName("fling");
ff.setDescription("ffff");
Lllll ll = new Lllll();
ll.setAge(88);
ll.setFf(ff);
try {
@SuppressWarnings("unchecked")
//将ff的属性和值都set到map中去
Map<String,Object> mapFf = PropertyUtils.describe(ff);
System.out.println(mapFf.get("name"));
@SuppressWarnings("unchecked")
//将ll的属性和值都set到map中去
Map<String,Object> mapLl = PropertyUtils.describe(ll);
System.out.println(((Fffff)mapLl.get("ff")).getName());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
public static void main(String[] args){
TestPropertyUtils tt = new TestPropertyUtils();
tt.test();
}
}
引入的包:commons-beanutils-1.7.0.jar,log4j-1.2.13.jar,commons-logging-1.1.jar
分享到:
相关推荐
主要介绍了Java反射获取class对象方式解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
BeanUtils.java CachedIntrospectionResults.java ClassUtils.java ...PropertyUtils.java ReflectionUtils.java ResourceUtils.java SerializationUtils.java StringUtils.java TypeUtils.java Validate.java
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
easymock-propertyutils 注意:此库未维护,可能已被取代 这个库允许你在使用时对参数使用 JavaBeans 风格的属性匹配
NULL 博文链接:https://m635674608.iteye.com/blog/2270455
Beanutils用了魔术般的反射技术,实现了很多夸张有用的功能,都是C/C++时代不敢想的。无论谁的项目,始终一天都会用得上它。...4.4 MethodUtils,动态调用方法 4.5 动态Bean 见用DynaBean减除不必要的VO和FormBean
PropertyUtils Property Unility Class RandomUtils Random Unility Class ResourceUtils Resource Unility Class SHA1Utils Sha1 Unility Class SerializableUtils Serializable Unility Class ...
1.1,beanutils propertyUtils类副本与反射副本使用及效率比较。 1.2,收藏CollectionUtils从一个列表中查找符合一定条件的对象。 2,太阳 2.1,发送邮件javax.mail完成邮件的发送和接收。 3,MyBatis 3.1,基本...
1.PropertyUtils 对标注NotNull注解的属性,检查其值是否为null 2.JsonUtils 用于获取json字符串中指定key的value 示例 json = {"name":"刘禅","age":"6","father":{"name":"刘备","age":"50","properties": {...
1:AES 加密解密 2:AuthUtils 授权相关的工具类 3:Base64 base64编码 ...23:PropertyUtils 属性工具类 24:QuerySqlUtil 25:RegexUtils 26:TestClass 28:UploadUtils 文件上传工具 29:UtilTest 30:VideoTool