分页助手PageHelper

匿名 (未验证) 提交于 2019-12-02 23:49:02

1、pageHelper环境搭建

<!--PageHelper依赖引入-->         <dependency>             <groupId>com.github.pagehelper</groupId>             <artifactId>pagehelper</artifactId>             <version>5.1.2</version>         </dependency>

2、配置文件:配置的是mybatis的pageHelper插件,mybatis插件已集成spring配置文件中

 第一种:直接在spring配置文件中进行书写

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">         <property name="dataSource" ref="dataSource"></property>         <!--mybatis 其它配置-->         <property name="plugins">             <array>                 <bean class="com.github.pagehelper.PageInterceptor">                     <property name="properties">                         <props>                             <!-- 分页的相关配置参数   用哪个数据库-->                             <prop key="helperDialect">mysql</prop>                         </props>                     </property>                 </bean>             </array>         </property>    </bean>

第二种:引入外部mybatis配置文件

<!--第二种分页配置文件方式-->         <property name="configLocation" value="classpath:sqlMapConfig.xml"></property>                     <!--外部文件  sqlMapConfig.xml  文件-->         <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration         PUBLIC "-//mybatis.org//DTD Config 3.0//EN"         "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration>     <plugins>         <plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>     </plugins> </configuration>

3、书写service层接口及实现类

4、测试

@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath*:spring/*.xml") public class TestPageHelper {      @Autowired     ProductService productService;     @Test     public  void test(){         productService.testFindByPageHelper(1,2);     } }

  

 

转载请标明出处:分页助手PageHelper
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!