Update 29.2.2. MongoTemplate.md

master
qibaoguang 2015-02-12 23:39:22 +08:00
parent f458ffa47c
commit cd9cb62685
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
### 29.2.2. MongoDBTemplate
Spring Data Mongo提供了一个[MongoTemplate](http://docs.spring.io/spring-data/mongodb/docs/current/api/org/springframework/data/mongodb/core/MongoTemplate.html)类它的设计和Spring的JdbcTemplate很相似。正如JdbcTemplate一样Spring Boot会为你自动配置一个bean你只需简单的注入它即可
```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Component;
@Component
public class MyBean {
private final MongoTemplate mongoTemplate;
@Autowired
public MyBean(MongoTemplate mongoTemplate) {
this.mongoTemplate = mongoTemplate;
}
// ...
}
```
具体参考MongoOperations Javadoc。