国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

jsp和controller數(shù)據(jù)交互工具類

2019-11-11 01:21:30
字體:
供稿:網(wǎng)友

1

2

import java.util.ArrayList;import java.util.List;import java.util.concurrent.ConcurrentHashMap;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.sPRingframework.cglib.beans.BeanCopier;import org.springframework.util.DigestUtils;public class CopyBeanUtils {	/**	 * Bean 對象屬性copy Util	 * 	 * @author 	 */	private static Logger logger = LoggerFactory.getLogger(CopyBeanUtils.class);	private static ConcurrentHashMap<String, BeanCopier> cache = new ConcurrentHashMap<String, BeanCopier>();	/**	 * @param source	 *            源對象class	 * @param target	 *            目標對對象class	 * @param sourceObj	 *            復制的源對象	 * @param useConverter	 * @return	 * @throws Exception	 */	public static <T> T copyBeanProperties( Class<T> target,			Object sourceObj, boolean useConverter) {		if (sourceObj == null)			return null;		T t;		try {			t = target.newInstance();		} catch (Exception e) {			logger.error("", e);			return null;		}		String key = sourceObj.getClass().getName() + target.getName();		BeanCopier copier = cache.get(key);		if (copier == null) {			copier = createBeanCopier(sourceObj.getClass(), target, useConverter, key);		}		copier.copy(sourceObj, t, null);		return t;	}	/**	 * 	 * 	 * @param sourceObj	 *            源對象	 * @param target	 *            目標對象	 * @param useConverter	 * @return	 * @throws Exception	 */	public static <T> T copyBeanProperties(Object sourceObj, T target,			boolean useConverter) {		if (sourceObj == null || target == null)			return null;		String key = sourceObj.getClass().getName()				+ target.getClass().getName();		BeanCopier copier = cache.get(key);		if (copier == null) {			copier = createBeanCopier(sourceObj.getClass(), target.getClass(),					useConverter, key);		}		copier.copy(sourceObj, target, null);		return target;	}	public static <T> List<T> copyListBeanPropertiesToList(List<?> sourceObjs,			List<T> targets, Class<T> targetType) {		if (sourceObjs == null || targets == null || targetType == null)			return null;		T t;		for (Object o : sourceObjs) {			try {				t = targetType.newInstance();				targets.add(copyBeanProperties(o, t, false));			} catch (InstantiationException e) {				logger.error("", e);			} catch (IllegalaccessException e) {				logger.error("", e);			}		}		return targets;	}		public static <T> List<T> copyListBeanPropertiesToList(List<?> sourceObjs,			 Class<T> targetType) {		List<T> targets=new ArrayList<T>();		return copyListBeanPropertiesToList(sourceObjs,targets,targetType);	}	private static String getHashKey(String str) {		if (str == null)			return null;		return DigestUtils.md5DigestAsHex(str.getBytes());	}	@SuppressWarnings({ "rawtypes" })	private static BeanCopier createBeanCopier(Class sourceClass,			Class targetClass, boolean useConverter, String cacheKey) {		BeanCopier copier = BeanCopier.create(sourceClass, targetClass,				useConverter);		cache.putIfAbsent(cacheKey, copier);		return copier;	}}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 临江市| 安溪县| 阿瓦提县| 汨罗市| 紫金县| 方正县| 勐海县| 鹤岗市| 镇康县| 浦东新区| 庄浪县| 龙海市| 望江县| 武乡县| 奉化市| 玉山县| 鹤山市| 博罗县| 叙永县| 忻城县| 连江县| 巴南区| 文成县| 长顺县| 商丘市| 湄潭县| 普兰店市| 澄迈县| 霸州市| 东安县| 商城县| 靖宇县| 威宁| 巴马| 聂拉木县| 阜平县| 花莲县| 昌乐县| 沙河市| 钟山县| 麻城市|