一、在pom.xml中添加依赖
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.8</version>
</dependency>
二、配置分页插件
<bean id="sqlSessionFactory"
class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="plugins">
<array>
<bean class="com.github.pagehelper.PageInterceptor">
<property name="properties">
<!-- config params as the following -->
<value>
param1=value1
</value>
</property>
</bean>
</array>
</property>
</bean>
三、ServiceImpl
public PageInfo<Book> selectAllBookList(Book book,int currentPage, int pageSize) {
PageHelper.startPage(currentPage, pageSize);
List<Book> bookList = cusDecDao.selectAllCusDecList(book);
PageInfo<Book> pageInfo = new PageInfo<>(bookList);
return pageInfo;
}
四、Controller
public String toIndex(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer rows, Book book, HttpServletRequest request, HttpSession session) {
//查询所有报关记录
PageInfo<Book> bookList = bookService.selectAllBookList(book,page,rows);
request.setAttribute("page", bookList);
return "search";
}
五、分页效果