Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在SpringRestController方法中从请求中提取查询参数?_Spring_Spring Boot_Rest Client - Fatal编程技术网

如何在SpringRestController方法中从请求中提取查询参数?

如何在SpringRestController方法中从请求中提取查询参数?,spring,spring-boot,rest-client,Spring,Spring Boot,Rest Client,URL:/api/v1/用户?类型=abc&公司=xyz 在API调用中,我们可以使用@QueryParam注释提取查询参数。但是,我们必须为映射定义查询参数键 @QueryParam("type") String type @QueryParam("company") String company 在这种情况下,我们有一些动态参数,比如page=2&limit=10&skip=20&type=abc。。。 我们正在使用rest客户端对不同的服务进行另一

URL:/api/v1/用户?类型=abc&公司=xyz

在API调用中,我们可以使用@QueryParam注释提取查询参数。但是,我们必须为映射定义查询参数键

@QueryParam("type") String type
@QueryParam("company") String company
在这种情况下,我们有一些动态参数,比如page=2&limit=10&skip=20&type=abc。。。 我们正在使用rest客户端对不同的服务进行另一次调用。在这里,我们必须将请求中接收到的所有查询参数传递给该服务


我们如何读取这些查询参数并将其添加到请求中?

您可以尝试使用映射并这样定义查询参数

@RequestParam Map<String,String> params
然后,当您发出请求时,您可以为映射是否包含特定参数创建一些逻辑,然后使用它:)



当您在没有特定参数的情况下定义@RequestParam时,它将提取所有参数并注入到映射中。

您可以尝试使用映射并以类似的方式定义queryparams

@RequestParam Map<String,String> params
然后,当您发出请求时,您可以为映射是否包含特定参数创建一些逻辑,然后使用它:)


当您定义@RequestParam而没有特定的参数作为目标时,它将提取所有参数并注入到映射中