spring boot使用MongoDB
## 前言
在spring boot使用MongoDB;
@Autowired
private MongoTemplate mongoTemplate;
public void save(Student s){
mongoTemplate.save(s);
}
public void remove(integer id){
Query query=new query(Criteria.where("id").is(id));
mongoTemplate.remove(query,Student.class);
}
public List<Student> query(Student s){
return mongoTemplate.findAll(Student.clss);
}
public void insertAll(List slist){
mongoTemplate.insertAll(slist);
}
public void insertAll2(List<T> list){
BulkOperations ops=mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED,T.class);
ops.insert(list);
ops.execute();
}