`
uule
  • 浏览: 6323335 次
  • 性别: Icon_minigender_1
  • 来自: 一片神奇的土地
社区版块
存档分类
最新评论

ConvertUtil - Dto转换类

 
阅读更多

 很简单,主要是注意抽象。

public class ConvertUtil {
	
	
	public static void convertToSnapshotDto(Snapshot model,SnapshotDto dto){
		if(model == null) return;
		
		if(dto == null)
			dto = new SnapshotDto();
		
		BeanUtils.copyProperties(model, dto);
		
		dto.setState(model.getState() != null ? model.getState().name() : null);
		dto.setInterval(model.getInterval() != null ? model.getInterval().name() : null);
	}
	
	
	public static List<SnapshotDto> convertCollectionToSnapshotDto(Collection<Snapshot> collection){
		if(collection == null || collection.size() == 0) return null;
		
		List<SnapshotDto> dtos = new ArrayList<SnapshotDto>();
		for(Snapshot snapshot : collection){
			SnapshotDto dto = new SnapshotDto();
			convertToSnapshotDto(snapshot,dto);
			dtos.add(dto);
		}
		
		return dtos;
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics