????????????????????????
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
使用Lists.transform
list 为源数据(复制对象)? price 为目标
//源数据
List<Pr> list = new ArrayList<>();
//使用lamda
List<DTO> price = Lists.transform(list, (entity) -> {
DTO vo = new DTO();
vo.setCode(entity.getCode());
vo.setName(entity.getCode());
vo.setId(entity.getId());
return vo;
});
//使用function
List<DTO> price = Lists.transform(list, new Function<Pr, DTO>() {
@Nullable
@Override
public DTO apply(@Nullable Pr entity) {
// 内部对象的转换操作
DTO vo = new DTO();
vo.setCode(entity.getCode());
vo.setName(entity.getName());
vo.setId(entity.getId());
return vo;
}
});
|