pagehelper / Mybatis-PageHelper

Mybatis通用分页插件
https://mybatis.io
MIT License
12.18k stars 3.13k forks source link

limit出现两次,如: LIMIT 1,5 LIMIT 1,5,导致sql报错 #40

Closed solarisy closed 7 years ago

solarisy commented 7 years ago

打印出来的sql语句,其中的LIMIT1,5有两次,导致sql报错

select * from t_weike   
  WHERE  `published` = ?   
    AND `publish_user_id` = ?  
    AND `deleted` = ?
    ORDER BY id desc LIMIT 1,5 LIMIT 1,5

我的环境:

Spring的applicationContext.xml配置如下:

    <!-- mybatis 配置 start -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:mybatis/*.xml"/>
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <value>reasonable=true</value>
                    </property>
                </bean>
            </array>
        </property>
    </bean>
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.benmei.weike.dao"/>
    </bean>
    <!-- mybatis 配置 end/ -->

Java代码如下:

        PageRowBounds pageRowBounds = new PageRowBounds(1, 5);
        List<Weike> list = weikeDao.searchWeike(weike,pageRowBounds);
        long total = pageRowBounds.getTotal();
abel533 commented 7 years ago

配置错了,如果使用了 starter ,就不要配置 plugins 里面的拦截器了。直接就可以用了。