当前位置: 首页 > news >正文

Java 属性拷贝 三种实现方式

第一种

List<OrederPayCustomer> orederPayCustomerList = this.list(queryWrapper);
List<CustomerResp>customerRespList=new ArrayList<>();for (OrederPayCustomer orederPayCustomer : orederPayCustomerList) {CustomerResp customerResp = new   CustomerResp();customerResp.setId(orederPayCustomer.getId());customerResp.setAppName(orederPayCustomer.getAppName());customerResp.setAppCode(orederPayCustomer.getAppName());customerResp.setStatus(orederPayCustomer.getStatus());customerResp.setCreatedBy(orederPayCustomer.getCreatedBy());customerResp.setCreatedTime(orederPayCustomer.getCreatedTime());customerRespList.add(customerResp);return customerRespList;
}

第二种

List<OrederPayCustomer> orederPayCustomerList = this.list(queryWrapper);
List<CustomerResp>customerRespList=new ArrayList<>();  customerRespList = orederPayCustomerList.stream().map(orederPayCustomer -> {CustomerResp customerResp = new         CustomerResp();customerResp.setId(orederPayCustomer.getId());     customerResp.setAppName(orederPayCustomer.getAppName());customerResp.setAppCode(orederPayCustomer.getAppName());customerResp.setStatus(orederPayCustomer.getStatus());customerResp.setCreatedBy(orederPayCustomer.getCreatedBy());customerResp.setCreatedTime(orederPayCustomer.getCreatedTime());customerRespList.add(customerResp);return customerRespList;
}).toList();

 第三种  不再使用创建对象的方式来去构建对象

List<OrederPayCustomer> orederPayCustomerList = this.list(queryWrapper);
List<CustomerResp>customerRespList=new ArrayList<>(); customerRespList = orederPayCustomerList.stream().map(orederPayCustomer -> {return CustomerResp.builder().id(orederPayCustomer.getId()).appName(orederPayCustomer.getAppName()).appCode(orederPayCustomer.getAppCode()).status(orederPayCustomer.getStatus()).createdBy(orederPayCustomer.getCreatedBy()).createdTime(orederPayCustomer.getCreatedTime()).build();
}).toList();
return customerRespList;

 简化版本

List<OrederPayCustomer> orederPayCustomerList = this.list(queryWrapper);return   orederPayCustomerList.stream().map(CustomerResp::CustomerBuild).toList();

 上面实现的CustomerBuild    

 数据库对象构建返回结果对象
public static CustomerResp CustomerBuild(OrederPayCustomer orederPayCustomer) {return CustomerResp.builder().id(orederPayCustomer.getId()).appName(orederPayCustomer.getAppName()).appCode(orederPayCustomer.getAppCode()).status(orederPayCustomer.getStatus()).createdBy(orederPayCustomer.getCreatedBy()).createdTime(orederPayCustomer.getCreatedTime()).build();
}
http://www.lryc.cn/news/415063.html

相关文章:

  • Java-变量,运算符,输入与输出
  • 五、一个quad同时支持pcie和sfp两种高速接口的ref时钟配置
  • AI辅助教育:九章大模型的数学辅导功能解析
  • 力扣刷题之3128.直角三角形
  • OD C卷 - 机场航班调度
  • uni-app中使用支付宝扫码插件并且在真机调试时使用(详细教程)
  • 每日学术速递8.5—1
  • 1、操作系统相关概念
  • 【ModelSim】仿真问题记录
  • 如何提高深度学习中数据运行的稳定性
  • 【连续数组】python刷题记录
  • JavaScript青少年简明教程:DOM和CSS简介
  • 架构师知识梳理(一):计算机硬件
  • 从根儿上学习spring 四 之run方法启动第一段
  • 智能闹钟如何判断用户已经醒了?
  • 【算法】动态规划解决背包问题
  • day09 工作日报表
  • C++学习之路(1)— 第一个HelloWorld程序
  • python3 pyside6图形库学习笔记及实践(三)
  • 03 库的操作
  • 嵌入式人工智能(44-基于树莓派4B的扩展板-LED按键数码管TM1638)
  • linux通过抓包工具tcpdump查看80端口访问量情况
  • Mac 上安装和卸载 SDKMAN 及管理多个 JDK
  • 字节测开一面面经
  • HTML 段落
  • 【Mind+】掌控板入门教程04 迷你动画片
  • 文件上传漏洞-HackBar使用
  • 鸿蒙媒体开发【相机数据采集保存】音频和视频
  • 【java基础】徒手写Hello, World!程序
  • 对 vllm 与 ollama 的一些研究