我想在Spring中根据Id删除一条记录。 但在数据库中id值是对象 例如:-
id: Object(34562341112313)
如何在Spring中删除这条记录?
最佳答案
你确实喜欢这样:
public void deleteRecord() {
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
Query searchQuery = new Query(Criteria.where("id").is(34562341112313));
mongoOperation.remove(searchQuery, Your_entity_class.class);
logger.info("Delete success");
}
这是我的现实例子:
/**
* Delete by condition(s).
*/
public void deleteJob() {
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
Query searchQuery = new Query(Criteria.where("company").is("DCV"));
mongoOperation.remove(searchQuery, Job.class);
logger.info("Đã xóa các công việc đăng bởi DCV.");
}
引用:http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/
关于java - 如何使用 Spring Data 删除 MongoDB 中的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37663444/