Spring Cloud Datastore REST Repositories

2024-01-12 09:34 更新

使用Spring Boot運(yùn)行時(shí),只需將此依賴(lài)項(xiàng)添加到pom文件即可將存儲(chǔ)庫(kù)公開(kāi)為REST服務(wù):

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>

如果您希望配置參數(shù)(例如路徑),則可以使用@RepositoryRestResource批注:

@RepositoryRestResource(collectionResourceRel = "trades", path = "trades")
public interface TradeRepository extends DatastoreRepository<Trade, String[]> {
}

例如,您可以使用curl http://<server>:<port>/trades檢索存儲(chǔ)庫(kù)中的所有Trade對(duì)象,或者通過(guò)curl http://<server>:<port>/trades/<trader_id>檢索任何特定交易。

您也可以使用curl -XPOST -H"Content-Type: application/json" -d@test.json http://<server>:<port>/trades/進(jìn)行交易,其中文件test.json包含Trade對(duì)象的JSON表示形式。

要?jiǎng)h除交易,您可以使用curl -XDELETE http://<server>:<port>/trades/<trader_id>

以上內(nèi)容是否對(duì)您有幫助:
在線(xiàn)筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)