关于mybatis一对多查询中PageHelper会因为一对多产生数据数目不正确问题

.XML文件


        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
    

    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    
      house.id as houseid , house.purpose as housepurpose , house.name as housename , house.house_card as househouseCard ,
      house.category as housecategory , house.type as housetype , house.area_structure as houseareaStructure , house.area_inner as houseareaInner ,
      house.area_share as houseareaShare , house.status as housestatus , house.community_id as housecommunityId , house.check_in as housecheckIn ,
      house.is_decorate as houseisDecorate , house.is_elevator as houseisElevator , house.is_identification as houseisIdentification ,
      house.remark as houseremark , house.owner_remark as houseownerRemark , house.parent_id as houseparentId ,
      house.sort as housesort , house.gmt_create as housegmtCreate , house.gmt_modified as housegmtModified
    
    
         htenants.id as htenantsid , htenants.user_image_url as htenantsuserImageUrl , htenants.user_image_id as htenantsuserImageId ,
      htenants.label as htenantslabel , htenants.owner_name as htenantsownerName , htenants.owner_phone as htenantsownerPhone ,
      htenants.owner_pic as htenantsownerPic , htenants.owner_type as htenantsownerType , htenants.status as htenantsstatus ,
      htenants.house_id as htenantshouseId , htenants.community_id as htenantscommunityId , htenants.proprietor_name as htenantsproprietorName ,
      htenants.proprietor_phone as htenantsproprietorPhone , htenants.proprietor_relation as htenantsproprietorRelation ,
      htenants.sex as htenantssex , htenants.gmt_create as htenantsgmtCreate , htenants.gmt_modified as htenantsgmtModified
    
    
      howner.id as hownerid , howner.user_image_url as howneruserImageUrl , howner.user_image_id as howneruserImageId ,
      howner.label as hownerlabel , howner.owner_name as hownerownerName , howner.owner_phone as hownerownerPhone ,
      howner.owner_pic as hownerownerPic , howner.owner_type as hownerownerType , howner.status as hownerstatus ,
      howner.house_id as hownerhouseId , howner.community_id as hownercommunityId , howner.proprietor_name as hownerproprietorName ,
      howner.proprietor_phone as hownerproprietorPhone , howner.proprietor_relation as hownerproprietorRelation ,
      howner.sex as hownersex , howner.gmt_create as hownergmtCreate , howner.gmt_modified as hownergmtModified
    
    
      hmember.id as hmemberid , hmember.user_image_url as hmemberuserImageUrl , hmember.user_image_id as hmemberuserImageId ,
      hmember.label as hmemberlabel , hmember.owner_name as hmemberownerName , hmember.owner_phone as hmemberownerPhone ,
      hmember.owner_pic as hmemberownerPic , hmember.owner_type as hmemberownerType , hmember.status as hmemberstatus ,
      hmember.house_id as hmemberhouseId , hmember.community_id as hmembercommunityId , hmember.proprietor_name as hmemberproprietorName ,
      hmember.proprietor_phone as hmemberproprietorPhone , hmember.proprietor_relation as hmemberproprietorRelation ,
      hmember.sex as hmembersex , hmember.gmt_create as hmembergmtCreate , hmember.gmt_modified as hmembergmtModified
    

    

    
    
    
    

重点就是
collection property=“houseMemberVOList” ofType=“org.jsola.pms.vo.HouseOwnerVO” column=“houseid” select=“selecthtenants”
在collection的时候 加个select=“selecthtenants” select中就是你需要的一对多中多的数据 select中就是查询的方法 column=“houseid” 就是你相关联的id。 在子查询(selecthtenants)中 #{houseid}来获取
DAO层

/**
     * 查询小区下的房屋业主,家属及租客
     * @param houseQuery 查询条件
     * @return 展示列表
     */
    List selectDoorPage (@Param("houseQuery") HouseQuery houseQuery);

impl

 PageInfo pageInfo = PageHelper.startPage(houseQuery.getPageNo(), houseQuery.getPageSize()).doSelectPageInfo(() ->  houseDAO.selectDoorPage(houseQuery));
        Page resultPage = new Page<>(pageInfo.getList(), pageInfo.getPageNum(), pageInfo.getPageSize(), (int) pageInfo.getTotal());

这样就能正常的配合PageHelper工具类了

你可能感兴趣的:(mybatis)