I get an example UriComponentsBuilder while learning spring boot. I don't know the meaning of UriComponentsBuilder and the function of UriComponentsBuilder.
public class UriComponentsBuilder extends Object implements UriBuilder, Cloneable. Builder for UriComponents . Typical usage involves: Create a UriComponentsBuilder with one of the static factory methods (such as fromPath(String) or fromUri(URI) )
The main advantages of UriComponentsBuilder are the flexibility of using URI template variables, and a possibility of injecting it directly into Spring Controller methods. All examples and configurations are available here on GitHub.
public class ServletUriComponentsBuilder extends UriComponentsBuilder. UriComponentsBuilder with additional static factory methods to create links based on the current HttpServletRequest.
public abstract class UriBuilder extends Object. URI template-aware utility class for building URIs from their components.
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.
It is a factory class for getting instances of UriComponents which are helpful for constructing URIs.
Please go through the tutorial below, examples are also given here.
http://www.baeldung.com/spring-uricomponentsbuilder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With