首页 > 其他分享 >apache commons包中的commons-beanutils

apache commons包中的commons-beanutils

时间:2022-12-02 11:31:55浏览次数:40  
标签:包中 name commons entity public apache Integer id String


public class Entity {

private Integer id = 5;
private String name = "rongxinhua";

public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

public String haha(){
return "Ha,Ha";
}

public void sayHelle(String name){
System.out.println(name + " say, Hello!");
}

public String countAges(int x, int y){
return "My Age is " + (x + y);
}

}



相关用法


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);

标签:包中,name,commons,entity,public,apache,Integer,id,String
From: https://blog.51cto.com/u_14230175/5906768

相关文章

  • spring boot替换jar包中引用的jar包(Unable to open nested entry 'BOOT-INF/lib/**.ja
    场景springboot项目,使用打jar包方式部署时,准备替换包中依赖时(不想重新打包),方法是使用压缩软件打开,直接复制替换掉相应依赖jar包,结果启动时报错Exceptioninthread"mai......
  • org.apache.catalina.core.StandardWrapperValve.invoke 在路径为/xxx的上下文中,Servl
    举个例子,后端向jsp中传递了一个参数是一个对象当jsp进行引用${bean.xxx}时bean中没有xxx属性,那么就会报这个错看看是不是jsp更新了对应的类没有更新解决方式很简单,要么j......
  • (收藏)apache comon 包集合等
    开源工具系列文章:ApacheCommonsLang(1):http://ray-yui.iteye.com/blog/1953020ApacheCommonsLang(2):http://ray-yui.iteye.com/blog/195......
  • 用apache common io包获得文件扩展名
    apachecommonio包包含了很多非常实用的工具类,比如连获得文件的扩展名都有了,比如:importorg.apache.commons.io.FilenameUtils;Stringextensi......
  • 【译】Apache Kafka 快速入门
    编译自官方文档。第1步:获取Kafka下载最新版本(当前为v3.3.1)的Kafka并解压:$tar-xzfkafka_2.13-3.3.1.tgz$cdkafka_2.13-3.3.1第2步:启动Kafka环境注......
  • Apache Tomcat 安全基线检查
    1禁止自动部署服务配置描述配置自动部署,容易被部署恶意或未经测试的应用程序,应将其禁用加固建议修改Tomcat根目录下的配置文件conf/server.xml,将host节点的autoDeploy属......
  • Apache Dubbo 多语言体系再添新员:首个 Rust 语言版本正式发布
    DubboRust定位为Dubbo多语言体系的重要实现,提供高性能、易用、可扩展的RPC框架,同时通过接入DubboMesh体系提供丰富的服务治理能力。本文主要为大家介绍DubboRu......
  • apache 日志轮询 linux cronolog
    Linux下运行的Web服务器Apache,默认日志文件是不分割的,一个整文件既不易于管理,也不易于分析统计。安装cronolog后,可以将日志文件按时间分割,易于管理和分析。cronolog安装配置......
  • Apache 配置虚拟主机三种方式
    一、基于IP 1.假设服务器有个IP地址为192.168.1.10,使用ifconfig在同一个网络接口eth0上绑定3个IP:[root@localhost root]# ifconfig eth0:1 192.168.1.11[root@localho......
  • Java中使用commons-io组件
    安装配置在其官网(CommonsIO–DownloadApacheCommonsIO)下载好之后,在项目中导入使用1、复制文件voidcopyFile(finalFilesrcFile,finalFiledestFile)//复......