Example usage for org.springframework.web.servlet.support ServletUriComponentsBuilder fragment

List of usage examples for org.springframework.web.servlet.support ServletUriComponentsBuilder fragment

Introduction

In this page you can find the example usage for org.springframework.web.servlet.support ServletUriComponentsBuilder fragment.

Prototype

@Override
public UriComponentsBuilder fragment(@Nullable String fragment) 

Source Link

Document

Set the URI fragment.

Usage

From source file:com.microservice.training.hal.HalBrowser.java

/**
 * Returns the View to redirect to to access the HAL browser.
 * /*ww w  . j a v  a2  s  . c  o  m*/
 * @param request must not be {@literal null}.
 * @param browserRelative
 * @return
 */
private View getRedirectView(HttpServletRequest request, boolean browserRelative) {

    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequest(request);

    UriComponents components = builder.build();
    String path = components.getPath() == null ? "" : components.getPath();

    if (!browserRelative) {
        builder.path(BROWSER);
    }

    builder.path(INDEX);
    builder.fragment(browserRelative ? path.substring(0, path.lastIndexOf("/browser")) : path);

    return new RedirectView(builder.build().toUriString());
}