@Repository
public interface ICommentRepository extends PagingAndSortingRepository<Comment, Integer> {
@Query(from Comment comment where comment.article.id = ?1)
Page<Comment> findAllArticleId(int articleId, Pageable page);
}
报错:The annotation @Query is disallowed for this location
解决方法:
首先要正确导入Query,
然后发现 @Query(from Comment comment where comment.article.id = ?1)
这一行少了""
改为
@Query("from Comment comment where comment.article.id = ?1")
本文介绍了一种常见的Spring Data JPA开发过程中遇到的问题——使用@Query注解时出现的错误,并提供了详细的解决方案。文章指出正确的导入方式及如何修正@Query语法中的常见错误。

1086

被折叠的 条评论
为什么被折叠?



