Apache CommonsApache Commons有很多子项目,常用的项目如下项目 作用BeanUtils 对Java Bean进行各种操作,复制对象,属性Codec 处理常用的编码,解码Collections 扩展Java集合框架的操作I/O 输入/输出工具的封装Lang java基本对象(java.lang) 方法的工具类包BeanUtils提供了一系列对java bean的操作,读取和设置属性值等@Datapublic class User { private String username; private String password;}12345User user = new User();BeanUtils.setProperty(user, "username", "li");BeanUtils.getProperty(user, "username");123map和bean的互相转换// bean->mapMap map = BeanUtils.describe(user);// map->beanBeanUtils.populate(user, map);1234我们将对象放在缓存中通常用redis中的hash,如下# 设置用户信息hset student name testhset student age 10123这种场景下map和bean的互相转换的工具类就特别有用Codec常见的编码,解码方法封装// Base64Base64.encodeBase64String(byte[] binaryData)Base64.decodeBase64(String base64String)// MD5DigestUtils.md5Hex(String data)// URLURLCodec.decodeUrl(byte[] bytes);URLCodec.encodeUrl(BitSet urlsafe, byte[] bytes);12345678910Collections交并差等操作// 判空CollectionUtils.isEmpty(collA);// 交集CollectionUtils.retainAll(collA, collB);// 并集CollectionUtils.union(collA, collB);// 差集CollectionUtils.subtract(collA, collB);// 判等CollectionUtils.isEqualCollection(collA, collB);12345678910I/OIOUtils对IO操作的封装// 拷贝流IOUtils.copy(InputStream input, OutputStream output);// 从流中读取内容,转为listList line = IOUtils.readLines(InputStream input, Charset encoding);1234FileUtils对文件操作类的封装