書き込みページ順DAO層に配置されMyBatisの - 「インタフェースと実装クラスのサービス層 - 」コントローラ(ウェブにおける)
これはMyBatisのが配置されている関連するプラグタブDAO層に作用します
<! - 分页插件- > < 依存> < groupIdを> com.github.pagehelper </ groupIdを> < たartifactId > pagehelper </ たartifactId > </ 依存関係>
<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);