Myatis和MybatisPlus常见分页方式
一、mybaits
- 原生limit分页
SELECT * FROM order_info limit #{pageNow},#{pageSize}
- 分页插件(ssm中,通过xml配置分页。springboot通过则通过配置文件)
PageHelper插件:PageHelper.startPage(pageNow,pageSize);List<OrderInfo> orderInfoList = orderInfoMapper.getOrderInfoList();PageInfo<OrderInfo> userPageInfo = new PageInfo<>(orderInfoList);return userPageInfo.getList();
- RowBounds进分页(极少落地)
二、MP分页
- 直接上分页插件配置
package com.ithuang.demo.config;import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class MybatisPlusConfig {@Beanpublic MybatisPlusInterceptor mybatisPlusInterceptor(){MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();interceptor.addInnerInterceptor(new PaginationInnerInterceptor());return interceptor;}
}
三、其他
mybatisplus可以和mybatis混合使用,也即:使用MP特性,处理基础的增删改查、使用Mybatis实现复杂的自定义SQL。