2016-12-02 101 views
1

我正在使用Spring web服务和MongoDb来保存我的数据。目前我的Repository类扩展了MongoRepository,并且其接口的obj被注入到了Controller中。 在MongoRepository接口中没有找到和删除特定实体的方法。我怎样才能做到这一点,而不必提供具体的实现?我需要同时进行手术。如何在MongoDB中使用MongoRepository在Spring中查找一次性删除

这里是在github上我的代码,如果它有用:https://github.com/RyanNewsom/DentistAppointmentSchedulerService

回答

1

我最终搞清楚了这一个了。我做了一个自定义类并使用了MongoTemplate。然后您可以使用mongoTemplate提交查询。它包含更多的mongo特定实现。

@Repository 
public class AppointmentCustomRepository { 
    @Autowired 
    MongoTemplate mongoTemplate; 

    public Appointment getAppointmentAndDelete(String id) { 
     return mongoTemplate.findAndRemove(Query.query(Criteria.where("id").is(id)), Appointment.class); 
    } 
} 
相关问题