功能:
1、产生长度为32的字符串,且不重复
2、将Map对象转化为制定的JavaBean对象
package com.acme.utils;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.beanutils.BeanUtils;
/**
* 公用工具类
* @author acme.w
* @version 1.0.0
*
*/
public class CommonUtils {
/**
*
* @return 不重复的字符串(长度:32)
*/
public static String uuid() {
return UUID.randomUUID().toString().replaceAll("-", "").toUpperCase();
}
/**
*
* @param bean
* @param map
* @return map --> bean: 将Map转换为Bean
* @throws Exception
*/
public static <T, K, V> T toBean(Class<T> bean, Map<K, V> map) throws Exception {
try {
T t = bean.newInstance();
BeanUtils.populate(t, map);
return t;
} catch (Exception e) {
throw e;
}
}
}