这是我的文件:
@Document(collection = "posts")
public class Post {
@Id
String id;
String title;
String description;
}
我正在尝试使用like运算符查询标题或描述中包含特定内容的文章。
我的仓库
public class PostsRepository extends MongoRepository<Post, String> {
@Query(value = "{ $or: [ { 'title' : ?0 }, { 'description' : ?0 } ] }")
Page<Post> queryByTitleOrDescription(String query, Pageable pageable);
}
我该如何在两个字段上使用LIKE进行查询,并在它们之间加入OR?