首页 > 解决方案 > Spring Boot - MongoDb 通过手动创建的查询查找

问题描述

在我的应用程序中,我手动创建了一些查询,然后我想简单地找到与创建的查询匹配的所有实体。为此,现在我必须创建一个 CustomXYRepository 接口和实现来调用 MongoOperations 的 find 方法。(例如:this.mongoOperation.find(query, AppointmentDao.class);)同样,我的查询是由应用程序本身构造的,因此我不会使用“静态”@Query 注释,我也想避免自定义存储库实现只为一条线。有没有可能在 Repository 接口中编写这样的方法?

public interface CalendarRepository extends MongoRepository<AppointmentDao, String> {
...
    /**
       * Find appointments by the given query.
       * 
       * @param query
       * @return
       */
      List<AppointmentDao> findByQuery(Query query);
...
}

非常感谢,祝您有美好的一天!

标签: springmongodbspring-bootmongorepository

解决方案


推荐阅读