//service 层拼
public Page<PersonInfoDTO> getPersonByJava() {
long startTime = System.currentTimeMillis();
IPage<PersonDO> personPage = personMapper.selectPage(new Page<>(),null);
IPage<AddressDO> addressPage = addressMapper.selectPage(new Page<>(),null);
//todo 获取 person 信息
List<PersonDO> personDOList = personPage.getRecords();
List<PersonInfoDTO> personInfoDTOList = new ArrayList<>();
//todo 获取所有 address 信息
List<AddressDO> addressDOList = addressPage.getRecords();
int personSize = personDOList.size();
int addressSize = addressDOList.size();
for (int i = 0; i < personSize ; i++) {
PersonDO personDO = personDOList.get(i);
PersonInfoDTO personInfoDTO = new PersonInfoDTO();
personInfoDTO.setName(personDO.getName());
personInfoDTO.setSex(personDO.getSex());
personInfoDTO.setId(personDO.getId());
for (int j = 0; j < addressSize; j++) {
AddressDO addressDO = addressDOList.get(j);
if (addressDO.getName().equals(personInfoDTO.getName())){
personInfoDTO.setAddress(addressDO.getAddress());
personInfoDTOList.add(personInfoDTO);
}
}
}
Page<PersonInfoDTO> personInfoDTOPage = new Page<>();
personInfoDTOPage.setRecords(personInfoDTOList);
long endTime = System.currentTimeMillis();
long usedTime = endTime - startTime;
System.out.println(usedTime);
return personInfoDTOPage;
}
<!--name 加了索引-->
<select id="getPersonByJoin" resultType="com.hpy.convertfoodemo.convert.entity.DTO.PersonInfoDTO">
select t1.id,
t1.name,
t1.sex,
t2.address
from test.person t1
left join test.address t2 on t1.name = t2.name
</select>
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.