搜尋
首頁Javaspringframework.web.client RestClient 是否處理 @requestParam

php小編香蕉將為大家解答一個關於Spring Framework中的問題:RestClient是否處理@RequestParam?在Spring Framework中,使用RestTemplate進行HTTP請求時,@RequestParam註解用於從請求URL中取得參數。那麼RestClient是否能夠正確處理@RequestParam註解呢?接下來,我們將詳細探討這個問題,幫助您更能理解並使用Spring Framework中的RestClient。

問題內容

我嘗試這樣做:

@getmapping("/db/video/getall")
public responseentity<list<videodto>> getallvideo(@requestparam string owneremail) {        
        return ....;
    }
import org.springframework.web.client.restclient;

restclient restclient = restclient.create("http://localhost:8095");

list<videodto> result = restclient.get()
    .uri("/db/video/getall")
    .accept(mediatype.application_json)
    .retrieve()
    .body(new parameterizedtypereference<list<videodto>>() {});
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot</artifactId>
    <version>3.2.1</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>6.1.2</version>
  </dependency>

但我找不到程式碼範例,顯示 restclient 如何將owneremail 作為@requestparam 傳遞。

我找到了 @pathvariable 程式碼範例。

那麼,restclient 是否處理 @requestparam ?

解決方法

對於 get 請求,您可以在 url 中新增查詢參數。 spring 的 uricomponentsbuilder 簡化了 uri 的操作。

restclient.get()
    .uri(uricomponentsbuilder.frompath("/db/video/getall")
            .queryparam("owneremail", "email").touristring())
    // ...

對於 post 請求,內文可以設定為 multivaluemap。 content-type 可以根據其內容推斷出來。

var parts = new LinkedMultiValueMap<String, Object>();
parts.add("ownerEmail", "emailValue");
restClient.post().uri("/db/video/getall").body(parts).retrieve().body(...);

以上是springframework.web.client RestClient 是否處理 @requestParam的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:stackoverflow。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

DVWA

DVWA

Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境