What is the meaning of UriComponentsBuilder?

Viewed 17931

I get an example UriComponentsBuilder while learning spring boot. I don't know the meaning of UriComponentsBuilder and the function of UriComponentsBuilder.

2 Answers

Yes, this used for constructing URI. Particularly useful when you want to invoke webservices in your class. Eg:

String baseUri = "/sample-uri"
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(uri);
builder.queryParam("id", "1");
String uri= builder.build().encode().toUriString();

It is evident that you can pass additional params, to this. This provide a clean and efficient way of creating uris than writing those as plain text.

Related