首页>代码>Apache Shiro+SpringMVC+Hibernate Search+Hibernate+Bootstrap企业信息管理系统基础框架搭建整合实例代码教程>/jeesite3/src/main/java/com/thinkgem/jeesite/common/mapper/BeanMapper.java
package com.thinkgem.jeesite.common.mapper; import java.util.Collection; import java.util.List; import org.dozer.DozerBeanMapper; import com.google.common.collect.Lists; /** * 简单封装Dozer, 实现深度转换Bean<->Bean的Mapper.实现: * * 1. 持有Mapper的单例. * 2. 返回值类型转换. * 3. 批量转换Collection中的所有对象. * 4. 区分创建新的B对象与将对象A值复制到已存在的B对象两种函数. * * @author calvin */ public class BeanMapper { /** * 持有Dozer单例, 避免重复创建DozerMapper消耗资源. */ private static DozerBeanMapper dozer = new DozerBeanMapper(); /** * 基于Dozer转换对象的类型. */ public static <T> T map(Object source, Class<T> destinationClass) { return dozer.map(source, destinationClass); } /** * 基于Dozer转换Collection中对象的类型. */ @SuppressWarnings("rawtypes") public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) { List<T> destinationList = Lists.newArrayList(); for (Object sourceObject : sourceList) { T destinationObject = dozer.map(sourceObject, destinationClass); destinationList.add(destinationObject); } return destinationList; } /** * 基于Dozer将对象A的值拷贝到对象B中. */ public static void copy(Object source, Object destinationObject) { dozer.map(source, destinationObject); } }

heng356 LV1
2月11日
zshldehao1 LV2
2月5日
zwjxxyxqf LV1
2024年11月1日
colecole LV3
2024年10月8日
HTML-WEB LV1
2024年5月22日
educationAAA LV11
2024年5月3日
2860615178 LV4
2024年5月1日
managment LV3
2024年4月17日
vluobo LV1
2024年3月19日
formatself1 LV2
2024年1月28日

missliu LV8
前天
哪里的完整版 LV8
4月1日
GakkiMarryMe LV9
3月25日
akittyboy LV9
2月24日
heng356 LV1
2月11日
林kkkkkk LV6
2月10日
zshldehao1 LV2
2月5日
sureivv LV2
1月9日
微信网友_7290593889931264
2024年12月10日
暂无贡献等级
sjwc88 LV3
2024年12月4日