java - springboot java mysql参数出现语法错误
问题描述
我有这个应用程序,java spring boot 和 mysql db。当我尝试运行以下查询时,我收到此错误。
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 'email ='rahul@gmail.com.com'' at line 1
有谁知道为什么?
@Query(value = "SELECT voucher_code FROM voucher INNER JOIN "
+ "offer ON offer.name = voucher.offer "
+ " email =:email", nativeQuery = true)
List<Voucher> getVouchers(@Param("email") String email);
解决方案
您在这两个条件之间缺少一些东西offer.name = voucher.offer
,email =:email
可能是一个WHERE
,也许是一个AND/OR
。我猜你想要这个:
@Query(value = "SELECT voucher_code FROM voucher INNER JOIN "
+ "offer ON offer.name = voucher.offer "
+ "WHERE email =:email", nativeQuery = true)
List<Voucher> getVouchers(@Param("email") String email);
推荐阅读
- python - 在 Python 的袖扣中使用带有键的列表以获得最佳拟合线
- ios - SwiftUI DragGesture onEnded 在某些情况下不会触发
- c# - 减少 C# 中的 Foreach 循环
- javascript - React native 需要一个字符串(用于内置组件)或一个类/函数(用于复合组件),但得到:object
- javascript - highcharts 列的表单数据系列
- visual-studio-code - 如何设置键盘映射以在 Visual Studio Code 中运行代码?
- php - 将 Symfony 项目部署到产品服务器时出现问题
- javascript - 支持“快速排序”算法
- python-3.x - 在两个不同的字符串中查找重复的字母
- python - 导入 pygmsh 模块后,Python 子进程会丢失我的 PATH 中的内容吗?