Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.mvc.method.annotation

public Class MvcUriComponentsBuilder

extends Object
Class Inheritance
Imports
java.lang.reflect.InvocationHandler, .Method, .Proxy, java.util.Arrays, .HashMap, .List, .Map, .Set, jakarta.servlet.http.HttpServletRequest, org.apache.commons.logging.Log, .LogFactory, org.springframework.beans.factory.NoSuchBeanDefinitionException, org.springframework.beans.factory.config.ConfigurableBeanFactory, org.springframework.cglib.core.SpringNamingPolicy, org.springframework.cglib.proxy.Callback, .Enhancer, .Factory, .MethodInterceptor, .MethodProxy, org.springframework.core.DefaultParameterNameDiscoverer, .MethodIntrospector, .MethodParameter, .ParameterNameDiscoverer, org.springframework.core.annotation.AnnotatedElementUtils, .SynthesizingMethodParameter, org.springframework.lang.Nullable, org.springframework.objenesis.ObjenesisException, .SpringObjenesis, org.springframework.util.AntPathMatcher, .Assert, .ObjectUtils, .PathMatcher, .ReflectionUtils, .ReflectionUtils.MethodFilter, .StringUtils, .SystemPropertyUtils, org.springframework.web.bind.annotation.RequestMapping, org.springframework.web.context.WebApplicationContext, org.springframework.web.context.request.RequestAttributes, .RequestContextHolder, .ServletRequestAttributes, org.springframework.web.method.HandlerMethod, org.springframework.web.method.annotation.RequestParamMethodArgumentResolver, org.springframework.web.method.support.CompositeUriComponentsContributor, org.springframework.web.servlet.DispatcherServlet, org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping, org.springframework.web.servlet.support.ServletUriComponentsBuilder, org.springframework.web.util.UriComponentsBuilder, org.springframework.web.util.pattern.PathPatternParser

Creates instances of org.springframework.web.util.UriComponentsBuilder by pointing to @RequestMapping methods on Spring MVC controllers.

There are several groups of methods:

Note

This class uses values from "Forwarded" (RFC 7239), "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers, if present, in order to reflect the client-originated protocol and address. Consider using the ForwardedHeaderFilter in order to choose from a central place whether to extract and use, or to discard such headers. See the Spring Framework reference for more on this filter.

Authors
Oliver Gierke, Rossen Stoyanchev, Sam Brannen, Juergen Hoeller
Since
4.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
public static class
MvcUriComponentsBuilder.MethodArgumentBuilder

Builder class to create URLs for method arguments.

public static interface
MvcUriComponentsBuilder.MethodInvocationInfo

Method invocation information.

Field Summary

Modifier and TypeField and Description
private final UriComponentsBuilder
private static final CompositeUriComponentsContributor
private static final Log
public static final String
MVC_URI_COMPONENTS_CONTRIBUTOR_BEAN_NAME

Well-known name for the CompositeUriComponentsContributor object in the bean factory.

private static final SpringObjenesis
private static final ParameterNameDiscoverer
private static final PathMatcher

Constructor Summary

AccessConstructor and Description
protected
MvcUriComponentsBuilder(UriComponentsBuilder baseUrl)

Default constructor.

Method Summary

Modifier and TypeMethod and Description
private static UriComponentsBuilder
public static <T> T
controller(Class<T>
the target controller
controllerType
)

Return a "mock" controller instance.

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance (never null)
fromController
(Class<?>
the controller to build a URI for
controllerType
)

Create a UriComponentsBuilder from the mapping of a controller class and current request information including Servlet mapping.

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance (never null)
fromController
(UriComponentsBuilder
the builder for the base URL; the builder will be cloned and therefore not modified and may be re-used for further calls.
builder
,
Class<?>
the controller to build a URI for
controllerType
)

An alternative to fromController(Class) that accepts a UriComponentsBuilder representing the base URL.

public static MvcUriComponentsBuilder.MethodArgumentBuilder

Returns:

a builder to prepare the URI String
fromMappingName
(String
the mapping name
mappingName
)

Create a URL from the name of a Spring MVC controller method's request mapping.

public static MvcUriComponentsBuilder.MethodArgumentBuilder

Returns:

a builder to prepare the URI String
fromMappingName
(UriComponentsBuilder
the builder for the base URL; the builder will be cloned and therefore not modified and may be re-used for further calls.
builder
,
String
the mapping name
name
)

An alternative to fromMappingName(String) that accepts a UriComponentsBuilder representing the base URL.

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance, never null
fromMethod
(Class<?>
the controller type
controllerType
,
Method
the controller method
method
,
Object...
argument values for the controller method
args
)

Create a UriComponentsBuilder from the mapping of a controller method and an array of method argument values.

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance (never null)
fromMethod
(UriComponentsBuilder
the builder for the base URL; the builder will be cloned and therefore not modified and may be re-used for further calls.
baseUrl
,
Class<?>
the controller type
controllerType
,
Method
the controller method
method
,
Object...
argument values for the controller method
args
)

An alternative to fromMethod(Class, Method, Object...) that accepts a UriComponentsBuilder representing the base URL.

public static UriComponentsBuilder

Returns:

a UriComponents instance
fromMethodCall
(Object
either the value returned from a "mock" controller invocation or the "mock" controller itself after an invocation
info
)

Create a UriComponentsBuilder by invoking a "mock" controller method.

public static UriComponentsBuilder

Returns:

a UriComponents instance
fromMethodCall
(UriComponentsBuilder
the builder for the base URL; the builder will be cloned and therefore not modified and may be re-used for further calls.
builder
,
Object
either the value returned from a "mock" controller invocation or the "mock" controller itself after an invocation
info
)

An alternative to fromMethodCall(Object) that accepts a UriComponentsBuilder representing the base URL.

private static UriComponentsBuilder
fromMethodInternal(UriComponentsBuilder builder, Class<?> controllerType, Method method, Object... args)

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance, never null
fromMethodName
(Class<?>
the controller
controllerType
,
String
the method name
methodName
,
Object...
the argument values
args
)

Create a UriComponentsBuilder from the mapping of a controller method and an array of method argument values.

public static UriComponentsBuilder

Returns:

a UriComponentsBuilder instance, never null
fromMethodName
(UriComponentsBuilder
the builder for the base URL; the builder will be cloned and therefore not modified and may be re-used for further calls.
builder
,
Class<?>
the controller
controllerType
,
String
the method name
methodName
,
Object...
the argument values
args
)

An alternative to fromMethodName(Class, String, Object...) that accepts a UriComponentsBuilder representing the base URL.

private static UriComponentsBuilder
private static String
getClassMapping(Class<?> controllerType)

private static Method
getMethod(Class<?> controllerType, final String methodName, final Object... args)

private static String
private static String
getPathMapping(RequestMapping requestMapping, String source)

private static String
getPathPrefix(Class<?> controllerType)

private static CompositeUriComponentsContributor
private static WebApplicationContext
public static <T> T
on(Class<T>
the target controller
controllerType
)

Return a "mock" controller instance.

public static MvcUriComponentsBuilder
relativeTo(UriComponentsBuilder baseUrl)

Create an instance of this class with a base URL.

private static String
public UriComponentsBuilder
withController(Class<?> controllerType)

An alternative to fromController(Class) for use with an instance of this class created via a call to relativeTo.

public MvcUriComponentsBuilder.MethodArgumentBuilder
withMappingName(String mappingName)

An alternative to fromMappingName(String) for use with an instance of this class created via relativeTo.

public UriComponentsBuilder
withMethod(Class<?> controllerType, Method method, Object... args)

An alternative to fromMethod(Class, Method, Object...) for use with an instance of this class created via relativeTo.

public UriComponentsBuilder
withMethodCall(Object invocationInfo)

An alternative to fromMethodCall(Object) for use with an instance of this class created via relativeTo.

public UriComponentsBuilder
withMethodName(Class<?> controllerType, String methodName, Object... args)

An alternative to fromMethodName(Class, String, Object...)} for use with an instance of this class created via relativeTo.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait