springboot整合PageHelper

引入依赖

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

application.properties

# 分页
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql

使用分页例子,只需要再查询前加入startPage即可

@Override
    public PageInfo<FoodmateDataSentenceLabel> getSentence(int fd_id, int No) {
        FoodmateDataSentenceLabelExample example = new FoodmateDataSentenceLabelExample();
        FoodmateDataSentenceLabelExample.Criteria criteria = example.createCriteria();
        criteria.andFdIdEqualTo(fd_id);
        // 分页
        PageHelper.startPage(No, 1);
        List<FoodmateDataSentenceLabel> foodmateDataSentenceLabelList =  foodmateDataSentenceLabelMapper.selectByExample(example);
        PageInfo<FoodmateDataSentenceLabel> pageInfo = new PageInfo<FoodmateDataSentenceLabel>(foodmateDataSentenceLabelList);
        return pageInfo;
    }

你可能感兴趣的:(JavaWeb,框架,springboot,pageHelper)