mybatis 使用 pageHelper 实现一对多分页

mybatis 中直接使用 collection 进行一对多关联查询,会造成 pageHelper 分页出错,数据会少很多。

简单一点的解决办法是使用子查询:

    
    
        
        
        
        
        
    
    
    
        
    
    
    
        
        
    

Request:

{
  "pageInfo": {
    "count": 10,
    "offset": 0,
    "page": 1,
    "pageSize": 0,
    "startRow": 0
  },
  "searchContent": "",
  "sortType": 1
}

Response:

{
  "code": "0",
  "reason": "成功",
  "data": {
    "total": 18,
    "list": [
      {
        "id": 22,
        "labels": [
          {
            "typeName": "求租",
            "gradeName": "A"
          },
          {
            "typeName": "求购",
            "gradeName": "C"
          },
          {
            "typeName": "出租",
            "gradeName": "B"
          },
          {
            "typeName": "出售",
            "gradeName": "A"
          }
        ],
        "customerIntentions": [
          {
            "type": 200101
          },
          {
            "type": 200102
          }
        ]
      },
      {
        "id": 21,
        "labels": [
          {
            "typeName": "线索",
            "gradeName": "D"
          }
        ],
        "customerIntentions": []
      },
      {
        "id": 17,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 24,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 11,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 10,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 16,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 9,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 8,
        "labels": [],
        "customerIntentions": []
      },
      {
        "id": 7,
        "labels": [],
        "customerIntentions": []
      }
    ],
    "pageNum": 1,
    "pageSize": 10,
    "size": 10,
    "startRow": 1,
    "endRow": 10,
    "pages": 2,
    "prePage": 0,
    "nextPage": 2,
    "isFirstPage": true,
    "isLastPage": false,
    "hasPreviousPage": false,
    "hasNextPage": true,
    "navigatePages": 8,
    "navigatepageNums": [
      1,
      2
    ],
    "navigateFirstPage": 1,
    "navigateLastPage": 2
  }
}

 

你可能感兴趣的:(java,mybatis)