A field annotated with @Id (org.springframework.data.annotation.Id) will be mapped to the '_id' field.
A field without an annotation but named 'id' will be mapped to the '_id' field.

 

需要包括maven依赖

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-commons</artifactId>
    <version>1.11.1.RELEASE</version>
</dependency>

 

spring配置

<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
    <property name="host" value="localhost"/>
</bean>

指定host。

参考

http://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/mongo.repositories.html

http://docs.spring.io/spring-data/data-mongo/docs/1.8.1.RELEASE/reference/html/#mongo.repositories

http://docs.spring.io/spring-data/data-mongo/docs/1.8.1.RELEASE/reference/html/#mapping-conventions

 

http://docs.spring.io/spring-data/data-mongo/docs/1.4.2.RELEASE/reference/html/mongo.repositories.html

相关文章:

  • 2021-08-02
  • 2021-06-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-12-23
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-06-08
相关资源
相似解决方案