MyBatis-plus 使用Select 注解进行自定义SQL 查询 报错Error querying database. Cause: java.sql.SQLSyntaxErrorExcept

报错信息:

Error querying database.  Cause: java.sql.SQLSyntaxErrorException: 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 29
### The error may exist in com/mall/Mapper/UserNeedMapper.java (best guess)
### The error may involve com.mall.Mapper.UserNeedMapper.getUserProductNeedList-Inline
### The error occurred while setting parameters
### SQL: SELECT      n.id AS n_id,     n.user_id,      n.product_id,      n.text,      n.update_time,     u.id AS u_id,      u.openid,      u.unionid,     u.nick_name,     u.avatar_url,     u.gender,     u.city,     u.register_time,     p.id AS p_id,      p.name,      p.description,     p.image,     p.price,     p.stock,     p.categories,     p.member_price,     p.tag FROM      `user_need` AS n JOIN      `user` AS u ON u.id = n.user_id JOIN      `product` AS p ON p.id = n.product_id; LIMIT ?
### Cause: java.sql.SQLSyntaxErrorException: 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 29

这个保持错很明显是sql 错误
我们把sql 提出来在 Sql 工具中进行查询
在这里插入图片描述
并没有任何问题啊?

还原一下场景

Mapper 配置
 @Select("SELECT \n" +
            "    n.id AS n_id,\n" +
            "    n.user_id, \n" +
            "    n.product_id, \n" +
            "    n.text, \n" +
            "    n.update_time,\n" +
            "    u.id AS u_id, \n" +
            "    u.openid, \n" +
            "    u.unionid,\n" +
            "    u.nick_name,\n" +
            "    u.avatar_url,\n" +
            "    u.gender,\n" +
            "    u.city,\n" +
            "    u.register_time,\n" +
            "    p.id AS p_id, \n" +
            "    p.name, \n" +
            "    p.description,\n" +
            "    p.image,\n" +
            "    p.price,\n" +
            "    p.stock,\n" +
            "    p.categories,\n" +
            "    p.member_price,\n" +
            "    p.tag\n" +
            "FROM \n" +
            "    `user_need` AS n\n" +
            "JOIN \n" +
            "    `user` AS u ON u.id = n.user_id\n" +
            "JOIN \n" +
            "    `product` AS p ON p.id = n.product_id;")
    IPage<UserProductNeedVo> getUserProductNeedList(Page<UserProductNeedVo> page);
service 实现
@Autowired
    UserNeedMapper userNeedMapper;
    public IPage<UserProductNeedVo> getUserProductNeedPage(int current, int size) {
        // 创建分页对象
        Page<UserProductNeedVo> page = new Page<>(current, size);

        // 调用分页查询
        return userNeedMapper.getUserProductNeedList(page);
    }
控制器
    @RequestMapping("/getUserProductNeed")
    public ResponseResult getUserProductNeed(@RequestParam int page,@RequestParam int limit) {
        IPage<UserProductNeedVo> productNeedPage = userNeedService.getUserProductNeedPage(page, limit);
        return ResponseResult.success(productNeedPage);
    }
百度加gpt 一番后无果
结论

直接说结论吧
在这里插入图片描述
眼尖的小伙伴应该已经发现了,这个有一个;号,它在sql 中代表该语句已经结束了

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值