Write page order dao layer disposed mybatis - "interfaces and implementation class service layer -" controller (web at)
Acting on the plug tab dao layer associated therewith is disposed mybatis
<!-- 分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency>
<configuration> <!-- 配置分页插件 --> <plugins> <plugin interceptor="com.github.pagehelper.PageHelper"> <!-- 设置数据库类型 Oracle,Mysql,MariaDB,SQLite,Hsqldb,PostgreSQL六种数据库--> <property name="dialect" value="mysql"/> </plugin> </plugins> </configuration>
然后在执行sql语句前加上
//分页处理
PageHelper.startPage(1, 10); List<TbItem> list = mapper.selectByExample(example);//执行sql语句,返回列表
//分页信息
PageInfo<TbItem> pageInfo=new PageInfo<>(list);
long total = pageInfo.getTotal();
System.out.println("共有商品:"+ total);