国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 集贤县| 金沙县| 白山市| 保康县| 五台县| 教育| 丹江口市| 萍乡市| 剑阁县| 宁海县| 洛浦县| 乌审旗| 寿光市| 桑植县| 邻水| 固原市| 景洪市| 阳原县| 锡林浩特市| 富民县| 乌兰县| 丹凤县| 屏东县| 江北区| 全州县| 门源| 台前县| 通海县| 邢台县| 株洲市| 侯马市| 黔西| 安泽县| 房山区| 泽普县| 台中市| 安吉县| 南涧| 南涧| 河西区| 兴安盟|