`
- 浏览:
244834 次
- 性别:
- 来自:
北京
-
PropertyUtils MethodUtils用法
-
package
rong.propertyUtils
;
-
-
import
java.util.Map;
-
import
org.apache.commons.beanutils.MethodUtils;
-
import
org.apache.commons.beanutils.PropertyUtils
;
-
-
public
class
TestPropertyUtils {
-
-
public
static
void
main(String[] args)
throws
Exception{
-
-
Entity entity =
new
Entity();
-
-
//通过
PropertyUtils
的getProperty方法获取指定属性的值
-
Integer id = (Integer)PropertyUtils
.getProperty(entity,
"id"
);
-
String name = (String)PropertyUtils
.getProperty(entity,
"name"
);
-
System.out.println(
"id = "
+ id +
" name = "
+ name);
-
-
//调用
PropertyUtils
的setProperty方法设置entity的指定属性
-
PropertyUtils
.setProperty(entity,
"name"
,
"心梦帆影"
);
-
System.out.println(
"name = "
+ entity.getName());
-
-
//通过
PropertyUtils
的describe方法把entity的所有属性与属性值封装进Map中
-
Map map = PropertyUtils
.describe(entity);
-
System.out.println(
"id = "
+ map.get(
"id"
) +
" name = "
+ map.get(
"name"
));
-
-
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(无参的情况)
-
System.out.println( MethodUtils.invokeMethod(entity,
"haha"
,
null
) );
-
-
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(1参的情况)
-
MethodUtils.invokeMethod(entity,
"sayHelle"
,
"心梦帆影"
);
-
-
//通过MethodUtils的invokeMethod方法,执行指定的entity中的方法(多参的情况)
-
Object[] params =
new
Object[]{
new
Integer(
10
),
new
Integer(
12
)};
-
String msg = (String)MethodUtils.invokeMethod(entity,
"countAges"
, params);
-
System.out.println(msg);
-
-
}
-
-
}
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
Beanutils用了魔术般的反射技术,实现了很多夸张有用的功能,都是C/C++时代不敢想的。无论谁的项目,始终一天都会用得上它。...4.4 MethodUtils,动态调用方法 4.5 动态Bean 见用DynaBean减除不必要的VO和FormBean
NULL 博文链接:https://m635674608.iteye.com/blog/2270455
easymock-propertyutils 注意:此库未维护,可能已被取代 这个库允许你在使用时对参数使用 JavaBeans 风格的属性匹配
主要介绍了Java反射获取class对象方式解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
1:AES 加密解密 2:AuthUtils 授权相关的工具类 3:Base64 base64编码 ...23:PropertyUtils 属性工具类 24:QuerySqlUtil 25:RegexUtils 26:TestClass 28:UploadUtils 文件上传工具 29:UtilTest 30:VideoTool
BeanUtils.java CachedIntrospectionResults.java ClassUtils.java ...PropertyUtils.java ReflectionUtils.java ResourceUtils.java SerializationUtils.java StringUtils.java TypeUtils.java Validate.java
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": {...
PropertyUtils Property Unility Class RandomUtils Random Unility Class ResourceUtils Resource Unility Class SHA1Utils Sha1 Unility Class SerializableUtils Serializable Unility Class ...