我爱编程

Spring boot 整合 pageHelper

2018-06-27  本文已影响0人  U_2647

1. 添加依赖

    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.3</version>
    </dependency>

最好是用最新版本

2. 注入 PageHelper

创建 配置类

import com.github.pagehelper.PageHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 分页工具配置
 * Create by ranzd on 2018/6/27
 *
 * @author cm.zdran@gmail.com
 */
@Configuration
public class PageHelperConfiguration {
    @Bean
    public PageHelper pageHelper() {
        PageHelper pageHelper = new PageHelper();
        Properties properties = new Properties();

        properties.setProperty("offsetAsPageNum","true");
        properties.setProperty("rowBoundsWithCount","true");
        properties.setProperty("reasonable","true");
        pageHelper.setProperties(properties);
        return pageHelper;
    }
}

参数说明:

3. 使用

下标从 1 开始,仅对之后的第一条语句生效。

    OrderExample example = new OrderExample();
    example.or().andLoginidEqualTo("usernem");
    PageHelper.startPage(1, 5);
    List<Order> result = orderMapper.selectByExample(example);
上一篇 下一篇

猜你喜欢

热点阅读