zoukankan      html  css  js  c++  java
  • 分页助手PageHelper

    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);
        }
    }
    

      

  • 相关阅读:
    Codeforces Round 546 (Div. 2)
    Codeforces Round 545 (Div. 2)
    Codeforces Round 544(Div. 3)
    牛客小白月赛12
    Codeforces Round 261(Div. 2)
    Codeforces Round 260(Div. 2)
    Codeforces Round 259(Div. 2)
    Codeforces Round 258(Div. 2)
    Codeforces Round 257 (Div. 2)
    《A First Course in Probability》-chaper5-连续型随机变量-随机变量函数的分布
  • 原文地址:https://www.cnblogs.com/-jian/p/11227909.html
Copyright © 2011-2022 走看看