简体   繁体   English

如何获取在RestTemplate springBoot应用程序中的url中传递的所有查询参数的列表?

[英]How to get list of all query params passed in url in RestTemplate springBoot application?

Working on a springboot based rest service using RestTemplate. 使用RestTemplate处理基于springboot的rest服务。 When query param is of limited number then it makes sense to define them as method parameters but I have a use case where a user can query for more than 1000 params. 当查询参数数量有限时,将它们定义为方法参数是有意义的,但是我有一个用例,用户可以查询1000多个参数。 Obviously I cann't make 1000 params method so how do I get all the query params - something which achievable from HttpRequest object but isn't exposed here via springboot based controller method as far as I know. 显然,我无法使用1000 params方法,因此如何获取所有查询参数-据我所知,这可以从HttpRequest对象实现,但此处未通过基于springboot的控制器方法公开。 So what should be done in this case? 那么在这种情况下应该怎么做?

For example if there's just one query param say query1 then below method will do desired work. 例如,如果只有一个查询参数,例如query1,则下面的方法将完成所需的工作。 What if I have 1000+ such query params? 如果我有1000多个这样的查询参数怎么办?

@RequestMapping(value = "urlPath", method = RequestMethod.GET)
    public ResponseEntity<?> method1(**@RequestParam("query1") Optional<String> fieldsOptional**)
    {
//do stuff
}

您可以简单地将@RequestParam Map<String, String> params到您的方法中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM