我试图从MYSQL获取记录,同时发布来自POSTMEN的GET请求。SQL查询在MYSQL控制台中工作,但在JPA中不工作。
@Repository
public interface RecipeRepository extends JpaRepository<Recipe, Long> {
@Query(value = "select * from Recipe where Recipe.id in (select Recipe_id
from Recipe_keywords where keywords like '%:keyword_rec%') ", nativeQuery = true)
List<Recipe> findByKeyword(@Param("keyword_rec") String keyword_rec);
}实际结果
未选定数据
预期结果
数据库中有一行可用,当与MYSQL控制台一起使用时,查询结果将返回行,这里也应该返回行。
通过按建议更新查询更新更新,在打印的output.Here查询中没有进行任何更改
select * from Recipe r where r.id in (select rk.Recipe_id from Recipe_keywords rk where rk.keywords like '%:keyword_rec%') 发布于 2019-07-16 21:20:17
将我的查询更改为
select * from Recipe r where r.id in (select rk.Recipe_id from Recipe_keywords rk where rk.keywords like %:keyword_rec%) 发布于 2019-07-16 20:33:47
因为在MySQL上编写的查询与为JPA编写的查询略有不同。
例如,SELECT * FROM Customer becomes "SELECT c FROM Customer c"
查看链接:https://www.oracle.com/technetwork/articles/vasiliev-jpql-087123.html
https://stackoverflow.com/questions/57064954
复制相似问题