MyBatisplus 使用IPage和Page分頁






@RequestMapping(value = "/cityList",method = RequestMethod.POST) public ResponseVo<IPage<GovernanceRegulationClosePo>> querySearchCityDataList(@RequestBody Map<String,Object>map){ IPage<GovernanceRegulationClosePo> page=governanceRegulationCloseService.getCityDataList(map); return new ResponseVo<>(true,page,UnicomResponseEnums.SUCCESS_OPTION); }
 IPage<GovernanceRegulationClosePo> getCityDataList(Map<String, Object> map);
@Override
    public IPage<GovernanceRegulationClosePo> getCityDataList(Map<String, Object> map) {
        String countyName = (String) map.get("countyName");
        String regionCode = (String) map.get("regionCode");
        Integer pageNum = (Integer) map.get("pageNum");
        Integer pageSize = (Integer) map.get("pageSize");
        String subRegionCode=regionCode.substring(0,4);

        Page<GovernanceRegulationClosePo> page=new Page<>(pageNum,pageSize);

        IPage<GovernanceRegulationClosePo> iPage=governanceRegulationCloseMapper.getCityDataList(page,countyName,subRegionCode);

        return iPage;
    }
IPage<GovernanceRegulationClosePo> getCityDataList(Page<GovernanceRegulationClosePo> page, @Param("countyName") String countyName,@Param("subRegionCode") String subRegionCode);
    <select id="getCityDataList" resultType="com.huitian.mine.domain.vo.GovernanceRegulationCloseVo">
        SELECT
        b.COUNTY_NAME,b.REGION_CODE,COUNT(MINE_NUMBER) AS count ,SUM(DAMAGED_AREA) AS sumDamagedArea ,SUM(PLAN_REPAIR_AREA) AS sumPlanRepairedArea ,SUM(REPAIRED_AREA) AS sumRepairedArea ,SUM(CAPITAL_USAGE) AS sumCapitalUsage
        FROM B_MINEREPAIRPROGRESSCLOSE b
        <if test="countyName!=''and countyName!=null">
            WHERE b.COUNTY_NAME=#{countyName}
        </if>
        GROUP BY b.COUNTY_NAME,b.REGION_CODE
        HAVING b.REGION_CODE LIKE CONCAT(#{subRegionCode},'%')
    </select>
public class GovernanceRegulationCloseVo {
     /**
      * 區縣名稱
      */
     private String countyName;
     /**
      * 所屬行政區編碼
      */
     private String regionCode;
     /**
      * 礦山總數
      */
     private Integer count;
     /**
      * 總損毀面積
      */
     private Long sumDamagedArea;
     /**
      * 總擬修復面積
      */
     private Long sumPlanRepairedArea;
     /**
      * 總已修復面積
      */
     private Long sumRepairedArea;
     /**
      * 總使用資金
      */
     private Double sumCapitalUsage;



}

添加配置類MyBatisPlusConfig 解決查詢不到總數

@EnableTransactionManagement // 開啟事務管理
@MapperScan("com.xxx.xxx.mapper") // 掃描mapper接口
@Configuration
public class MyBatisPlusConfig {

    /**
     * 分頁插件
     * @return
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
    
}

 

 

 

 

測試

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM