之前我们整合过SSM框架,可以查询数据库数据,项目中一般不会全部查询所有数据,为了美观和性能,都是采用分页形式查询数据
一:pom.xml导入pagehelper.jar
<!-- https://mvnrepository.com/artifact/com.github.pagehelper/pagehelper -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.10</version>
</dependency>
二:在 MyBatis 配置 xml 中配置拦截器插件
之前我们没有单独的mybatis配置文件,都是集成在applicationContext.xml中的,现在我们需要重新创建新的mybatis配置文件
三:在applicationContext.xml中引入该文件并配置
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <!-- 注意其他配置 --> <property name="plugins"> <array> <bean class="com.github.pagehelper.PageInterceptor"> <property name="properties"> <!--使用下面的方式配置参数,一行配置一个 --> <value> params=value1 </value> </property> </bean> </array> </property> </bean>
四:在代码中使用