php小编香蕉将为大家解答一个关于spring framework中的问题:restclient是否处理@requestparam?在spring framework中,使用resttemplate进行http请求时,@requestparam注解用于从请求url中获取参数。那么restclient是否能够正确处理@requestparam注解呢?接下来,我们将详细探讨这个问题,帮助您更好地理解和使用spring framework中的restclient。
问题内容
我尝试这样做:
@getmapping("/db/video/getall")public responseentity> getallvideo(@requestparam string owneremail) { return ....; }
登录后复制
import org.springframework.web.client.restclient;restclient restclient = restclient.create("http://localhost:8095");list result = restclient.get() .uri("/db/video/getall") .accept(mediatype.application_json) .retrieve() .body(new parameterizedtypereference>() {});
登录后复制
org.springframework.bootspring-boot3.2.1org.springframeworkspring-web6.1.2
登录后复制
但我找不到代码示例,显示 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();parts.add("ownerEmail", "emailValue");restClient.post().uri("/db/video/getall").body(parts).retrieve().body(...);
登录后复制
以上就是springframework.web.client RestClient 是否处理 @requestParam的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2621941.html