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 ...
随机推荐
- 公网IP被别人恶意解析的后果
在网上看的一个案例,说是自己网站的IP被别的域名恶意解析了,恶意网站没有备案,IP地址为没有备案的域名提供了正常的网站服务,导致对应的IP也被封了. 检查方法:telnet xxx.me 80端口不通 ...
- spoj periodni
题解: dp 方程弄出来就好做了 代码: #include<bits/stdc++.h> ,M=; typedef int arr[N]; typedef long long ll; in ...
- centos7源码安装Python3的前提条件
centos7源码安装Python3的前提条件: # yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline- ...
- 使用md5加密算法完成简单的登录和注册功能
原理: 登录:后端controller层获取到客户的密码,通过下面代码:new Sha256Hash(pwd).toHex();将密码转换成md5散列,生成一个新的字符串与数据库的值进行比对,根据不同 ...
- Caffe中Interp层的使用
最近实验当中借鉴了FPN网络,由于FPN网络对图片shape有要求,采用了两种方式,其一是在data_layer.cpp中,对原图进行padding操作:其二是需要对特征图进行类似crop操作,使得两 ...
- SVG路径PATH
SVG路径PATH 在使用之前建议下个PS或者FLASH玩玩里面的钢笔工具(FLASH里的钢笔工具比PS里的好用) PATH用到的指令: M----(X Y):移动到 Z----(none):关闭路径 ...
- nginx——Nginx 处理事件模型
Nginx 的连接处理机制在不同的操作系统会采用不同的 I/O 模型,要根据不同的系统选择不同的事件处理模型,可供选择的事件处理模型有:kqueue .rtsig .epoll ./dev/poll ...
- 磁性窗体设计C#(二)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- 入门项目 A4 db_handler 数据操作文件
''' 数据处理层 ''' from conf import settings # 以下代码中有提前定义的路径函数,需要导入配置文件包下面的设置模块 import json # 以下代码中有需要序列化 ...
- Mysql 复制一个新表
1.复制表结构及数据到新表CREATE TABLE 新表 SELECT * FROM 旧表这种方法会将oldtable中所有的内容都拷贝过来,当然我们可以用delete from newtable;来 ...