Is there a Java method that encodes a collection of parameters as a URL query component?

后端 未结 5 924
逝去的感伤
逝去的感伤 2021-01-12 12:56

Is there a widely-used Java library that does something like what dojo.objectToQuery() does? E.g. (assuming the use of HttpCore\'s HttpParams object, but any key-value mappi

5条回答
  •  一个人的身影
    2021-01-12 13:51

    There are plenty of libraries that can help you with URI building (don't reinvent the wheel). Here is one to get you started:


    org.springframework:spring-web:4.2.5.RELEASE

    import org.springframework.web.util.UriComponentsBuilder;
    ...
    return UriComponentsBuilder.fromUriString(url).queryParam(key, value).build().toUri();
    

    See also: GIST > URI Builder Tests

提交回复
热议问题