关于把返回参数封装到EbookResp的拷贝过程的问题
来源:3-7 封装请求参数和返回参数

weixin_慕婉清6290234
2022-11-10
老师您好,关于把返回参数封装到EbookResp的拷贝过程,有个问题
List<Ebook> ebookList = ebookMapper.selectByExample(ebookExample);
List<EbookResp> respList = new ArrayList<>();
for (Ebook ebook : ebookList) {
EbookResp ebookResp = new EbookResp();
BeanUtils.copyProperties(ebook, ebookResp);
respList.add(ebookResp);
}
这里先要定义一个ebookResp
EbookResp ebookResp = new EbookResp();
把ebook先拷贝到ebookResp,
再通过respList.add(ebookResp);拷贝到respList呢?
为什么不能直接写成:
BeanUtils.copyProperties(ebook, respLis);
写回答
1回答
-
甲蛙
2022-11-10
我记得BeanUtils.copyProperties不支持列表的复制,同学可以按你自己的想法写写看,如果实现了,可以把代码贴出来
00
相似问题