猿问

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);


慕仙森
浏览 119回答 1
1回答

喵喵时光机

您在两个条件之间缺少一些东西offer.name = voucher.offer,email =:email可能是 a&nbsp;WHERE,也许是 a&nbsp;AND/OR。我猜你想要这个:@Query(value&nbsp;=&nbsp;"SELECT&nbsp;voucher_code&nbsp;FROM&nbsp;voucher&nbsp;INNER&nbsp;JOIN&nbsp;" &nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;"offer&nbsp;ON&nbsp;offer.name&nbsp;=&nbsp;voucher.offer&nbsp;" &nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;"WHERE&nbsp;email&nbsp;=:email",&nbsp;nativeQuery&nbsp;=&nbsp;true) List<Voucher>&nbsp;getVouchers(@Param("email")&nbsp;String&nbsp;email);
随时随地看视频慕课网APP

相关分类

Java
我要回答