04-体验一下apache组织封装的BeanUtil工具包
apache 自己为程序员们封装了一个专门用于处理的工具类,其功能有(数据类型会自动转成与JavaBean相关的)
map转javabean
javabean转map
javabean对象复制
获取javabean对象属性值
设置javabean对象属性值…………
两个相关jar包文件 Build Path到项目当中去
commons-beanutils-1.9.2.jar
commons-logging-1.2.jar

1.将Map转换成JavaBean对象
/**
* 刘诗华
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception { Map<String, Object> m=new HashMap<String, Object>();
m.put("id", "28");
m.put("userName", "刘诗华");
m.put("password", "123456"); User user=new User(); //BeanUtils.copyProperties(dest, orig); dest:目标 orig:源
BeanUtils.copyProperties(user,m);
System.out.println(user); //结果:User(id=28, userName=刘诗华, password=123456) Integer id = user.getId(); //我们设置给Map集合的时候,给的是一个字符串,BeanUtils工具自动帮我们转换成包装类Integer类型
System.out.println(id);
}
2.JavaBean对象复制数据
/**
* 刘诗华
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
User orig=new User(28,"罗小胖","456456"); //源对象
User dest=new User(); //目标对象 空对象
BeanUtils.copyProperties(dest,orig); //JavaBean对象复制数据
System.out.println(dest);
//User(id=28, userName=罗小胖, password=456456)
}
3.设置Date时间格式转换
/**
* 申请注册时间格式
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
//源数据
Map<String, Object> m=new HashMap<String, Object>();
m.put("id", "");
m.put("userName", "刘诗华");
m.put("password", "123456");
m.put("hireDate", "2018/11/19"); //目标数据
User user=new User(); //时间数据格式对象
DateConverter converter=new DateConverter(); //converter.setPattern("yyyy-MM-dd HH:mm:ss"); //单个数据格式
//一组时间格式
String[] pattern=new String[3];
pattern[0]="yyyy-MM-dd HH:mm:ss";
pattern[1]="yyyy-MM-dd";
pattern[2]="yyyy/MM/dd";
converter.setPatterns(pattern); //如果Id上面没有数据,则设置为null
IntegerConverter integerConverter=new IntegerConverter(null);
ConvertUtils.register(integerConverter, Integer.class); //注册Date时间对象格式
ConvertUtils.register(converter, Date.class);
//开始复制数据信息
BeanUtils.copyProperties(user, m); System.out.println(user);
//User(id=null, userName=刘诗华, password=123456, hireDate=Mon Nov 19 00:00:00 CST 2018)
}
04-体验一下apache组织封装的BeanUtil工具包的更多相关文章
- 如何在Ubuntu 18.04上安装Apache Web服务器
一. apt库安装 1.在终端输入更新检查命令,sudo apt-get update 2. 在更新完成后(如果不想检查更新,也可直接输入此步)输入:sudo apt-get install apac ...
- Log4J是Apache组织的开源一个开源项目,通过Log4J,可以指定日志信息输出的目的地,如console、file等。Log4J采用日志级别机制,请按照输出级别由低到高的顺序写出日志输出级别。
Log4J是Apache组织的开源一个开源项目,通过Log4J,可以指定日志信息输出的目的地,如console.file等.Log4J采用日志级别机制,请按照输出级别由低到高的顺序写出日志输出级别. ...
- Ubuntu 18.04安装配置Apache Ant
Ubuntu 18.04安装配置Apache Ant 文章目录 Ubuntu 18.04安装配置Apache Ant 下载 执行以下命令 `/etc/profile`中配置环境变量 载入配置 测试 执 ...
- 如何在Ubuntu 16.04上安装Apache Web服务器
转载自:https://www.howtoing.com/how-to-install-the-apache-web-server-on-ubuntu-16-04 介绍 Apache HTTP服务器是 ...
- Ubuntu 16.04 集成安装Apache+PHP+Kerberos+LDAP+phpLDAPadmin
一.安装Apache 1.1.安装Apache apt-get update apt-get install apache2 过程如下: root@duke01:~# apt-get update命中 ...
- 百度云的ubuntu16.04.1部署Apache服务器+Django项目
使用Apache和mod_wsgi部署Django 是一种久经考验的将Django投入生产的方法. mod_wsgi是一个Apache模块,可以托管任何Python WSGI应用程序,包括Django ...
- Ubuntu 18.04上安装Apache, MySQL, PHP, LAMP
1.安装 Apache $ sudo apt update && sudo apt install apache2 中间会遇到停顿询问是否继续, 输入 y 然后 回车. 2.测试 Ap ...
- Ubuntu20.04 体验和美化
Ubuntu20.04美化和体验 windows用久了,换下系统也挺好的.ubuntu20.04优化后,用起来蛮舒服的. 系统配置 1.修改软件源 Ubuntu默认是国外的软件源, 我们可以手动切换为 ...
- Ubuntu12.04 下修改Apache端口号
1:$sudo vim /etc/apache2/ports.conf NameVirtualHost *:80Listen 8090 #将此行的80修改成8090 2:sudo vim /etc/a ...
随机推荐
- day71 菜单的排序 点击被选中
菜单的排序:(给菜单设置权重,权重高的让他显示在上面) from django import template from django.conf import settings from collec ...
- List集合1
一.List接口介绍 List继承自Collection接口,是单列集合的一个重要分支,习惯性的会将实现List接口的对象称为List集合 二.List接口3个特点 1.有序(有序不是顺序,有序指的是 ...
- 成功解决android studio打包报错
Win7系统,Android Studio 版本2.3.1,对cpp-empty-test使用了 cocos compile -p android --android-studio,命令 编译打包AP ...
- Django安装遇到的问题
因为mac一般自带的有python解释器,如果重新安装了新的解释器,并且想默认使用的话,需要配置一下环境变量. 在使用python解释器的时候,可以用命令:which python 来确定当前使用的时 ...
- python自学第13天 hashlib,re模块
import hashlib sha=hashlib.sha3_512()#定义加密成什么格式 sha.update('how to use sha1 in 年后 '.encode('utf-8')) ...
- 蓝牙协议分析(11)_BLE安全机制之SM
1. 前言 注1:此SM是Security Manager的缩写,非彼SM,大家不要理解歪了! 书接上文,我们在“蓝牙协议分析(10)_BLE安全机制之LE Encryption”中介绍了BLE安全机 ...
- ReactiveCocoa进阶
1.ReactiveCocoa常见操作方法介绍. 1.1 ReactiveCocoa操作须知 所有的信号(RACSignal)都可以进行操作处理,因为所有操作方法都定义在RACStream.h中,而R ...
- Unity在UI界面上显示3D模型/物体,控制模型旋转
Unity3D物体在UI界面的显示 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...
- python 进程之间的数据共享
from multiprocessing import Process,Manager import os def f(d,n): d[os.getpid()] = os.getppid()#对字典d ...
- github与github网站push神器
GitBook.Editor(全英文,无汉化) 链接: http://pan.baidu.com/s/1slIZ5jJ 密码: q9mw source tree (汉化中文) 本地需要安装git客户端 ...