MongoDB 测试数据,导入 MongoDB
https://gitee.com/shizidada/moose-resource/raw/master/shici_item.json
重命名 collection
shici_item ==> poetry_item
SpringBoot MongoDB 依赖
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-data-mongodbartifactId>dependency>
application.yml 添加配置
spring: data: mongodb: host: localhost port: 27017 database: shicimingju
创建实体和 mongodb 文档对应映射
/** * @author taohua * @Document 和 mongodb 集合名称对应 * */@Data@EqualsAndHashCode(callSuper = false)@Document(collection = "poetry_item")public class PoetryEntity {
/** * 主键 id */ @Id private String id; /** * @Field mongodb 字段进行对应映射 */ @Field("poetry_name") private String poetryName; @Field("poetry_content") private String poetryContent; @Fie