当前位置:网站首页>BeanUtils.copyProperties无法复制不同List集合问题解决 Lists.transform函数
BeanUtils.copyProperties无法复制不同List集合问题解决 Lists.transform函数
2022-07-28 05:17:00 【wang0112233】
<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;
}
});边栏推荐
- Interpretation of afnetworking4.0 request principle
- Duoyu security browser will improve the security mode and make users browse more safely
- 7. < tag string and API trade-offs> supplement: Sword finger offer 05. replace spaces
- Anaconda common instructions
- 11.< tag-动态规划和子序列, 子数组>lt.115. 不同的子序列 + lt. 583. 两个字符串的删除操作 dbc
- HashSet add
- Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions
- 面试了一位38岁程序员,听说要加班就拒绝了
- Interpreting the source code of cfrunloopref
- How does Alibaba use DDD to split microservices?
猜你喜欢

MySQL practice 45 lectures

Scope, execution process and life cycle of bean

Duoyu security browser will improve the security mode and make users browse more safely

Read the paper -- a CNN RNN framework for clip yield prediction

阿里怎么用DDD来拆分微服务?

First acquaintance with C language (1)

Have you ever seen this kind of dynamic programming -- the stock problem of state machine dynamic programming (Part 2)

MySQL date and time function, varchar and date are mutually converted

Scanf function of input and output function in C language

SSLError
随机推荐
Activation functions sigmoid, tanh, relu in convolutional neural networks
【SLAM】LVI-SAM解析——综述
Advanced assignment method of ES6 -- Deconstruction assignment
2022 summer practice (first week)
7. < tag string and API trade-offs> supplement: Sword finger offer 05. replace spaces
Eccv2022 | 29 papers of Tencent Youtu were selected, including face security, image segmentation, target detection and other research directions
Professor dongjunyu made a report on the academic activities of "Tongxin sticks to the study of war and epidemic"
[internal mental skill] - creation and destruction of function stack frame (C implementation)
Oracle用sql查询某张表的字段信息(字段类型、长度等)
yandex robots txt
Antd setfieldsvalue warning problem cannot use 'setfieldsvalue' until you use 'getfielddecorator' or
How should programmers keep warm when winter is coming
[paper notes] - low illumination image enhancement - zeroshot - rrdnet Network - 2020-icme
The research group passed the thesis defense successfully
How to send and receive reports through outlook in FastReport VCL?
oracle查看锁表语句、解锁方法
Check box error
Online sql to XML tool
11.< tag-动态规划和子序列, 子数组>lt.115. 不同的子序列 + lt. 583. 两个字符串的删除操作 dbc
【idea插件神器】教你如何使用IDEA一键set实体类中所有属性