Java一对多结构的封装方法
来源:互联网 发布:ubuntu qq2016 编辑:程序博客网 时间:2024/05/17 18:43
封装方法:
public Collection<AddLabourCostDetailReturnDto> echoData(String userId) { List<AddLabourCostDetailDto> list = compactDao.echoData(userId); if (list.size() == 0) { return Collections.EMPTY_LIST; } Map<Integer, AddLabourCostDetailReturnDto> map = new HashMap(); for (AddLabourCostDetailDto dto : list) { AddLabourCostDetailReturnDto rdto = map.get(dto.getEnterpriseId()); if (ValidateUtil.objectIsNull(rdto)) { rdto = new AddLabourCostDetailReturnDto(); rdto.setEnterpriseName(dto.getEnterpriseName()); rdto.setEnterpriseId(dto.getEnterpriseId()); List<AddLabourCostDetailProjectsDto> projects = new ArrayList<>(); rdto.setProjects(projects); map.put(dto.getEnterpriseId(),rdto); } rdto.getProjects().add(new AddLabourCostDetailProjectsDto(dto.getProjectId(),dto.getProjectName())); } Collection<AddLabourCostDetailReturnDto> enterprises = map.values(); return enterprises;}
一、AddLabourCostDetailReturnDto 类(最终要的结构)
public class AddLabourCostDetailReturnDto { private Integer enterpriseId; private String enterpriseName; private List<AddLabourCostDetailProjectsDto> projects; public Integer getEnterpriseId() { return enterpriseId; } public void setEnterpriseId(Integer enterpriseId) { this.enterpriseId = enterpriseId; } public String getEnterpriseName() { return enterpriseName; } public void setEnterpriseName(String enterpriseName) { this.enterpriseName = enterpriseName; } public List<AddLabourCostDetailProjectsDto> getProjects() { return projects; } public void setProjects(List<AddLabourCostDetailProjectsDto> projects) { this.projects = projects; }}
二、 AddLabourCostDetailDto 类(数据库查出的结构)
public class AddLabourCostDetailDto { private Integer enterpriseId; private String enterpriseName; private Integer projectId; private String projectName; public Integer getEnterpriseId() { return enterpriseId; } public void setEnterpriseId(Integer enterpriseId) { this.enterpriseId = enterpriseId; } public String getEnterpriseName() { return enterpriseName; } public void setEnterpriseName(String enterpriseName) { this.enterpriseName = enterpriseName; } public Integer getProjectId() { return projectId; } public void setProjectId(Integer projectId) { this.projectId = projectId; } public String getProjectName() { return projectName; } public void setProjectName(String projectName) { this.projectName = projectName; }}三、 AddLabourCostDetailProjectsDto 类
public class AddLabourCostDetailProjectsDto { private Integer projectId; private String projectName; public AddLabourCostDetailProjectsDto(){} public AddLabourCostDetailProjectsDto(Integer projectId, String projectName) { this.projectId = projectId; this.projectName = projectName; } public Integer getProjectId() { return projectId; } public void setProjectId(Integer projectId) { this.projectId = projectId; } public String getProjectName() { return projectName; } public void setProjectName(String projectName) { this.projectName = projectName; }}
阅读全文
0 0
- Java一对多结构的封装方法
- ibaties 一对多封装
- 自定义回调一对多的方法
- mybatis一对多的查询方法详解
- java socket一对多的通信
- JAVA 一对多关系
- java 一对多
- java一对多整合
- hibernate一对一、一对多、多对多的配置方法
- java获取系统时间的封装方法
- Java 一种Impl类的封装方法
- java类的封装与构造方法
- hibernate 一对多的2中设置方法
- 针对一对多等方法出现问题的分析
- Atitit. C# java 的api 目录封装结构映射总结
- JPA的一对多
- Hibernate的一对多
- Java-Map集合的应用-一对多的映射…
- python strip() 函数和 split() 函数的详解及实例
- json_encode解析gbk出null值
- select根据后台值选中
- NOIP 2017 Senior 5
- win7 64bit 企业版 编译Hadoop2.7.2源码+插件+部署伪分布式开发环境
- Java一对多结构的封装方法
- 1022. D进制的A+B (20) PAT乙级真题
- 链队列
- STM32F4的ADC 配置
- 位平方和
- httpclient下载图片转base64
- IO流
- 解决EXT自定义树的排序 remoteSort =true 用在store; 和sortable:true 用在column里的一个字段上
- 面试题整理--java中的参数传递(值传递、引用传递)