mybatis-plus page分頁


實例

包 com.baomidou.mybatisplus.extension.plugins.pagination

/** * 分頁查詢 * @param * @param * @return */ @ApiOperation(value = "分頁查詢", notes = "分頁查詢") @GetMapping("/page" ) public R findPage(@RequestParam(required = false,defaultValue = "1") Integer pageNum, @RequestParam(required = false,defaultValue = "10") Integer pageSize, @RequestParam(required = false) String dataSourceName, @RequestParam(required = false) String ip, @RequestParam Integer dataSourceType) { return R.ok(aggDatasourceService.findPage(pageNum,pageSize,dataSourceName,ip,dataSourceType)); }
    @Override
    public Page<AggDataSource> findPage(Integer pageNum, Integer pageSize, String dataSourceName, String ip,Integer dataSourceType){
        Page<AggDataSource> page = new Page<>(pageNum, pageSize); //new page (當前頁,當前大小)
        return this.baseMapper.find(page, dataSourceName, ip,dataSourceType);    
      //把參數傳遞給mapper方法即可,它會自動在執行sql的時候包裝一下,包裝內容其實是limt 得語句 select count(1) from(select * from user)  limit 5 offset 0 ;
}
    <select id="find" resultType="com.zxgeo.data.quartz.api.entity.AggDataSource">

            SELECT
                datasource_id,
                datasource_name,
                ip,
                port,
                SCHEMA,
                user_name,
                db_type,
                datasource_type,
                create_time,
                update_time
            FROM
                "agg_datasource"
            WHERE
                 del_flag = 0
                 and datasource_type = #{dataSourceType}
                <if test="dataSourceName!=null and dataSourceName!=''">
                    and datasource_name like concat('%', #{dataSourceName}, '%')
                </if>
                <if test="ip!=null and ip!=''">
                    and ip like concat('%', #{ip}, '%')
                </if>
      </select>

 


免責聲明!

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



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