mybatis分页插件pagehelper

pom.xml添加依赖


<dependency>
    <groupId>com.github.pagehelpergroupId>
    <artifactId>pagehelperartifactId>
    <version>4.1.6version>
dependency>

mybatis配置文件添加节点


<plugins>
    <plugin interceptor="com.github.pagehelper.PageHelper">
        
        <property name="helperDialect" value="Mysql"/>
    plugin>
plugins>
方法
public void demo(){

    SqlSession session = MyBatisUtil.getSession();
    HuaMapper huaMapper = session.getMapper(HuaMapper.class);
    //pageNum 页码 pageSize 每页显示多少条
    PageHelper.startPage(2,8);
    ArrayList list = huaMapper.getHuaList();

    PageInfo list1 = new PageInfo(list);
    for(Hua h : list){
        System.out.println("id="+h.getId()+"  name="+h.getName());
    }
}


你可能感兴趣的:(mybatis分页插件pagehelper)