![](/img/trans.png)
[英]Spring request mapping to a different method for a particular path variable value
[英]Mapping request params/ path variable to Dto in GET request in Spring
我想創建一個 controller,它將返回頁面 object。 我將需要Pageable
頁面具有頁碼及其大小(不能大於 50)和一些將成為搜索條件的變量。 如果這是一個 POST 請求,它可能如下所示:
public Page<SomeDto) getDto(@RequestBody @Valid RequestDto requestDto, Page pageRequest)
但是,它是一個 GET 請求,因此不能/不應該使用@RequestBody
。 此外,我想要類似於@Valid 的東西,以便 Spring 會自動拒絕錯誤的請求。
我想知道是否:
我想避免使用某種代碼:
public String updateFoos(@RequestParam Map<String,String> allParams) {}
無論使用什么 HTTP 方法,每個 HTTP 請求都可以有一個 HTTP 主體(因此也有一個@RequestBody
)。 However, it is not a good REST API design to use a HTTP body for GET request (cf. https://martinfowler.com/articles/richardsonMaturityModel.html )
您可以使用 @PathVariable 或 @RequestParam arguments 進行 bean 驗證,您只需將所需的注釋放在這些注釋旁邊
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.