分页插件PageHelp 和 解决MySQL server version for the right syntax to use near ‘LIMIT 10‘ at line 1问题

1.导入依赖

<dependency>
    <groupId>com.github.pagehelper</groupId>
    <artifactId>pagehelper</artifactId>
    <version>5.0.2</version>
</dependency>

2.在Spring-dao中进行文件配置

<!--配置SqlSessionFactory-->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="configLocation" value="classpath:sqlMapConfig.xml"></property>

        <!-- 传入PageHelper的插件 -->
        <property name="plugins">
            <array>
                <!-- 传入插件的对象 -->
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">mysql</prop>
                            <prop key="reasonable">true</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>

    </bean>

3.1在Service层中需要传入 Page 和 limit

public ResultMsg<Product> findAll(Integer page, Integer limit);
public ResultMsg<Product> findAll(Integer page,Integer limit) {

        ResultMsg<Product> resultMsg = new ResultMsg<Product>();

        resultMsg.setCode(0);

        //使用分页插件完成分页
        //page 和limit由前端页面给出
        PageHelper.startPage(page,limit);
        PageInfo<Product> pageInfo = new PageInfo<Product>(productMapper.findAll());
        
        //获取查询到的集合
        resultMsg.setData(pageInfo.getList());

        //获取查询数据的总条数
        resultMsg.setCount(pageInfo.getTotal());

        resultMsg.setMsg("成功响应");

        return resultMsg;
    }

3.2在Controller层

//查询
    @RequestMapping("findAll")
    @ResponseBody
    public ResultMsg<Product> findAll(Integer page,Integer limit){
        return productService.findAll(page,limit);
    }

注意:

在 Mapper.xml文件的sql语句中最后不要添加“ ;” 号   不然会报错;

报错类型:

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 10' at line 1

原因

利用Log4j打印的结果

 Preparing: select * from t_product; LIMIT 10 

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
这个错误信息"check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line "是指在你MySQL语句中存在语错误,需要根据你的MySQL服务器版本来使用正确的语法。 这个错误通常发生在SQL语句的某一行的附近。具体的语法错误需要根据你的SQL语句来确定,可能是缺少了某个关键字、拼写错误、或者错误使用了某个符号。你可以参考MySQL的官方文档来查找正确的语法,并且确保你的SQL语句与你的MySQL服务器版本兼容。可以尝试使用调试工具来逐行检查你的SQL语句,找出错误所在并进行修正。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [check the manual that corresponds to your MySQL server version for the right syntax to use near](https://blog.csdn.net/cdliker/article/details/106815722)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [your MySQL server version for the right syntax to use near ‘(0) NOT NULL, `endTime` datetime(0) NO](https://download.csdn.net/download/weixin_38515573/13688019)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [check the manual that corresponds to your MySQL server version for the right syntax to use near解决...](https://blog.csdn.net/qq_35623773/article/details/109752080)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值