spring mongodb用法

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

原文地址:https://www.cnblogs.com/silvestris/p/5165154.html