1. 增加 Spring Data?mongoDB jar 包
compile'org.springframework.boot:spring-boot-starter-data-mongodb'
2. application.yml 增加 mongoDB 配置
spring.data.mongodb.uri=mongodb://{username}:{password}@{host}:{port}/{database}
3. 使用JPA 方式來操作?mongoDB
3.1??定義與?mongoDB 交互的Entity
@Document 定義?mongoDB 文檔名稱
@Indexed 創(chuàng)建索引
? ??unique = true 創(chuàng)建唯一索引
? ? background = true 后臺創(chuàng)建索引
? ? expireAfterSeconds?= 10 * 60 設(shè)置600秒過期時間(默認(rèn)秒窝爪,到期便會自動刪除該條數(shù)據(jù))
定義與?mongoDB 交互的Entity
3.2 創(chuàng)建?Repository 層 (繼承 MongoRepository 類)
創(chuàng)建?Repository 層
3.3 具體 Service 實現(xiàn)
具體?Service?實現(xiàn)