mybatis分页之mybatis-plus

1.在pom.xml文件中加入依赖

       <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>${mybatis-plus.version}</version>
        </dependency>

2.在mybatis-config.xml文件中加入如下配置

   

<plugins>
        <!-- 分页查询插件 -->
        <plugin interceptor="com.baomidou.mybatisplus.plugins.PaginationInterceptor">
            <property name="dialectType" value="mysql" />
        </plugin>
    </plugins>

3在controller中使用

   

@PostMapping("orderlist.api")
    @ApiOperation(value = "分页查询", produces = MediaType.APPLICATION_JSON_VALUE)
    public Object memberOrderlist(@RequestBody DriverDto dto, HttpServletRequest request, HttpServletResponse response) {....................

      Page<BizOrderlist> page = new Page<BizOrderlist>(dto.getPage() == null ? 1 : dto.getPage() , dto.getPageSize() == null ? 15 : dto.getPageSize()); //初始化分页条数,如果传入的值为空在默认第一页,15条。

      Parameter orderparameter = new Parameter(getService(), "getOrderlist").setParam(page,params); //在servie中获取list,传递分页Page和查询参数
      Page<BizOrderlist>  orderList = (Page<BizOrderlist>) provider.execute(orderparameter).getResult();

4在service中使用

  

 public Page<BizOrderlist> getOrderlist(Page<BizOrderlist> page,Map<String, Object> params) {
        
        List<BizOrderlist> orderlist = (List<BizOrderlist>) ((OrderListMapper) mapper).getOrderList(page,param1,params2,params3);
        page = page.setRecords(orderlist);  //查出的list调用setRecords
        return page;

5mapper中接口类

 

public interface OrderListMapper extends BaseMapper<BizOrderlist> {
    /**
     *
     * 方法说明
     *
     * @author

     */
    List<BizOrderlist> getOrderList(Pagination  page,@Param("param1") Double param1...........);

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值