其实一直都在使用常用工具类,只是从没去整理过,今天空了把一些常用的整理一下吧
怎么使用的一看就明白,另外还有注释,最后的使用pom引入的jar包
public class ApacheCommonsTest { /** * 从一个entity中把属性复制进另外一个entity中 * * @throws Exception */ @Test public void testCopyNewBean() throws Exception { StuForm form = new StuForm("lee", 18, 1, new Date(), true); Stu stu = new Stu(); BeanUtils.copyProperties(form, stu); System.out.println(stu.toString()); } /** * base64 加密解密 * * @throws Exception */ @Test public void testBase64Code() throws Exception { String name1 = "hello, my name is lee~"; System.out.println("Before: " + name1); String name2 = Base64.encodeBase64String(name1.getBytes()); System.out.println("After encode: " + name2); String name3 = new String(Base64.decodeBase64(name2)); System.out.println("After decode: " + name3); String url1 = "www.lee.com.cn"; System.out.println("URL Before: " + url1); String url2 = Base64.encodeBase64URLSafeString(url1.getBytes()); System.out.println("URL After decode: " + url2); String url3 = new String(Base64.decodeBase64(url2)); System.out.println("URL After decode: " + url3); } /** * commons 下 collection 工具包 * * @throws Exception */ @Test public void testCollection() throws Exception { OrderedMap om = new LinkedMap (); om.put("one", 1); om.put("two", "2"); om.put("three", "three"); om.put("fore", 4); om.put("five", "5"); System.out.println(om.firstKey()); System.out.println(om.nextKey("fore")); System.out.println(om.previousKey("five")); System.out.println("=============================="); BidiMap bm = new TreeBidiMap(); bm.put("three", "3"); bm.put("five", "isfive"); System.out.println(bm.getKey("isfive").toString()); System.out.println(bm.get("three")); // 交换key和value BidiMap newMap = bm.inverseBidiMap(); System.out.println(newMap.size()); System.out.println("=============================="); Bag
commons-codec commons-codec 1.10 org.apache.commons commons-collections4 4.1 commons-configuration commons-configuration 1.10
附上地址: