欢迎使用CSDN-markdown编辑器

来源:互联网 发布:使用另一个php的变量 编辑:程序博客网 时间:2024/06/05 23:54

mybatis的分页是集运内存的分页,先将全部数据查询到内存中,然后取出偏移量的记录,所以需要重新生成它的sql查询语句,而真正生成Statement并执行sql的语句是StatementHandler接口的某个实现,所以需要配置一个拦截起拦截select * from 这条查询语句,并对其进行改造。
1. spring-mybatis中配置拦截器

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">        <property name="dataSource" ref="dataSource" />        <!-- 自动扫描mapping.xml文件 -->        <property name="mapperLocations" value="classpath:com/group7/entity/*.xml"></property>        <property name="plugins">            <array>                <bean class="com.github.pagehelper.PageHelper">                    <property name="properties">                        <value>                            dialect=oracle                            reasonable=true                        </value>                    </property>                </bean>            </array>        </property>    </bean>

2.我使用的是springMVC+mybatis+oracle,所以我直接在service层中调用pageHelper的startPage方法
`PageHelper.startPage(pageNum, 4);

    List<Product> products = productService.selectProduct();`

startPage后面的第一个方法名带“select”的查询语句会被在底层改造,成为物理层分页查询语句

0 0
原创粉丝点击