MybatisPlus 简单分页

  1. 分页插件config
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

//Spring boot方式
@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
public class MybatisPlusConfig {

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}
  1. 使用
    传入pageNum pageSize
public IPage
selectArticlePage(int pageNum, int pageSize) { Page
page = new Page<>(pageNum,pageSize); return articleMapper.selectPage(page, null); //第二个参数可以传wrapper条件查询 }
  1. 效果
    传入 pageNum 1 pageSize 2
    result:
{
    "records": [
        {
            "author": "jesse",
            "createTime": "2019-03-30T23:00:38",
            "content": "2e2b8e32-bd1c-4eb7-b088-4ca5840b1ffc",
            "title": "474e26a2"
        },
        {
            "author": "jesse",
            "createTime": "2019-03-30T23:00:40",
            "content": "8e4bbd32-1fd8-4ba2-8608-5881892a8abc",
            "title": "5d6c0643"
        }
    ],
    "total": 4,
    "size": 2,
    "current": 1,
    "searchCount": true,
    "pages": 2
}

分页所需的元素都有了

你可能感兴趣的:(MybatisPlus 简单分页)