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

首頁 > 編程 > JSP > 正文

jsp和controller數據交互工具類

2019-11-11 00:34:19
字體:
來源:轉載
供稿:網友

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;	}}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 孝义市| 武义县| 湟源县| 托克托县| 开远市| 龙胜| 平利县| 托里县| 蓬安县| 湟中县| 介休市| 平果县| 澳门| 梨树县| 东平县| 黔东| 秦安县| 灵武市| 汉沽区| 瑞丽市| 汨罗市| 桦甸市| 梅河口市| 休宁县| 三台县| 长海县| 甘洛县| 武宁县| 周口市| 乃东县| 朝阳县| 惠安县| 吉水县| 衢州市| 巫山县| 金坛市| 福海县| 太原市| 镇平县| 彰化县| 武冈市|