ConvertUtil

来源:互联网 发布:淘宝商城男装秋装 编辑:程序博客网 时间:2024/06/05 12:02

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

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

 

0 0
原创粉丝点击