1. Add Maven dependencies

<! Pagehelper </groupId> <artifactId> PageHelper </artifactId> pageHelper </artifactId> The < version > 4.4.1 < / version > < / dependency >Copy the code

2. Use config for configuration

import com.github.pagehelper.PageHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.util.Properties; /** * create PageHelper by CatalpaFlat on 2017/8/28. private Logger logger = LoggerFactory.getLogger(MyBatisPagConfig.class); @Bean public PageHelperpageHelper() {
        logger.info(MyBatis pagination plugin PageHelper);
        PageHelper pageHelper = new PageHelper();
        Properties p = new Properties();
        p.setProperty("offsetAsPageNum"."true");
        p.setProperty("rowBoundsWithCount"."true");
        p.setProperty("reasonable"."true");
        pageHelper.setProperties(p);
        returnpageHelper; }}Copy the code

3, use,

PageHelper.startPage(page, rows); //page: current page rows: how many rows are displayed on each pagetype,request,name); PageInfo<Object> pageInfo = new PageInfo<Object>(list); long total = pageInfo.getTotal(); //total: indicates the total number of entriesCopy the code