![](/img/trans.png)
[英]Request method 'GET' not supported in Dockerized SpringBoot REST api
[英]SpringBoot Rest API Get Method
I am building REST API using SpringBoot, this REST API accept more than one data from consumer like eg empId, empName, empDept. 在我當前的代碼中,我使用@RequestParam
注釋從請求中訪問查詢參數值。 但我看到我們也可以使用@PathVariable
從 URI 的占位符中獲取數據。
想知道使用@PathVariable
@RequestParam
或其他東西獲取多輸入請求的最佳實踐是什么?
想象一下。 如果您有用戶列表:
GET /users (here it lists all your users)
您可能會點擊一個用戶來訪問他的詳細信息:
GET /users/{id}
您將這個{id}
用作@PathVariable
您可能希望使用@RequestParam
過濾用戶:
GET /users?name=tst&age=21
並且您的 GET /users 有這些請求參數供您過濾:
@RequestParam(value ="name")
@RequestParam(value ="age")
通常,@PathVariable 用於“getByAnything”等情況,例如getUserById
和一個 Url 只能有一個占位符變量(理想)。 如果您的 API 有多個變量,您的選擇是 @RequestParam。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.