Spring BeanUtils简单使用
2024-10-18 22:34:38
引入包
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.</version>
</dependency>
main执行
package com.gwzx.pay; import java.util.Map;
import java.util.Map.Entry; import org.apache.commons.beanutils.BeanUtils; public class S { public static void main(String[] args) {
// TODO Auto-generated method stub
try {
// 1: 属性复制
Student2 s1 = new Student2(, "张三", , Boolean.FALSE);
Student2 s2 = new Student2();
BeanUtils.copyProperties(s2, s1);
System.out.println("1:" + s2.getName()); // 2: 属性放入map
Map<String, String> map = BeanUtils.describe(s2);
for (Entry<String, String> o : map.entrySet()) {
System.out.println(o.getKey() + "=" + o.getValue());
}
map.clear();
// 不会放入s2
map.put("aa", "bb");
// 覆盖s2
map.put("id", "");
map.put("bool", "true"); // 3: Map值 动态放入s2对象中
BeanUtils.populate(s2, map);
System.out.println(s2.toString()); } catch (Exception e) {
// TODO: handle exception
}
} }
最新文章
- 在SQLSERVER2008中建立数据库复制碰到的问题
- android 入门-布局
- 基于HTML5的电信网管3D机房监控应用
- 开发中遇到的angularJs的小问题
- 小公司生存,一般活过第一年,就能撑3年(读书笔记:成败关键,关键是你是否拥有现金流客户)good
- 考察printf函数返回值
- was性能调优
- 工作中常用Git指令操作
- CODEFORCES ROUND #761 ANALYSES BY TEAM:RED &; BLACK
- [cb]ScriptableWizard 创建向导
- Jmeter接口测试参数化实例图文示例
- 不要再混淆js的substring和substr了!(附js所有字符串方法)
- 在Spring Boot中使用 @ConfigurationProperties 注解, @EnableConfigurationProperties
- Intellij IDEA 文件修改提示星号
- Win10年度更新开发必备:VS2015 Update 2正式版下载汇总
- SpringBoot系列十二:SpringBoot整合 Shiro
- 熟悉使用ConfigParser库读写配置文件
- nodejs(五)同步异步--USING SETTIMEOUT INSTEAD OF SETINTERVAL TO FORCE SERIALIZATION
- centos下安装必要组件(相当于apt-get install install build-essential)
- Spring Boot与Mybatis 借助Fastjson快速完成数据解析入库