本文整理汇总了Java中org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromCurrentRequest方法的典型用法代码示例。如果您正苦于以下问题:Java ServletUriComponentsBuilder.fromCurrentRequest方法的具体用法?Java ServletUriComponentsBuilder.fromCurrentRequest怎么用?Java ServletUriComponentsBuilder.fromCurrentRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.servlet.support.ServletUriComponentsBuilder
的用法示例。
在下文中一共展示了ServletUriComponentsBuilder.fromCurrentRequest方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fixLink
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入方法依赖的package包/类
Object fixLink(Object value) {
if (!(value instanceof String)) {
return value;
}
String href = (String) value;
Matcher urlWithServiceNameMatcher = urlWithServiceNamePattern.matcher(href);
Matcher standardUrlMatcher = standardUrlPattern.matcher(href);
if (!standardUrlMatcher.matches() && urlWithServiceNameMatcher.matches()) {
String possibleServiceName = urlWithServiceNameMatcher.group(1);
log.debug("Possible service name: " + possibleServiceName);
if (services.contains(possibleServiceName)) {
log.debug("Service found");
String gatewayPath = serviceRouteMapper.apply(possibleServiceName);
String originalRestPath = urlWithServiceNameMatcher.group(2);
ServletUriComponentsBuilder servletUriComponentsBuilder = ServletUriComponentsBuilder.fromCurrentRequest();
UriComponents uriComponents = servletUriComponentsBuilder.replacePath(gatewayPath).path(originalRestPath).build();
log.debug("Mapping " + value + " to " + uriComponents);
return uriComponents.toString();
}
}
return href;
}
示例2: buildFileUrl
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入方法依赖的package包/类
/**
* Build a downLoadUrl for the file identified by the given fileId. If this method is called outside of a
* request context ( system initialization for example) the server context is used for generating a relative path
*/
private String buildFileUrl(String fileId)
{
if (RequestContextHolder.getRequestAttributes() != null)
{
ServletUriComponentsBuilder currentRequest = ServletUriComponentsBuilder.fromCurrentRequest();
UriComponents downloadUri = currentRequest.replacePath(FileDownloadController.URI + '/' + fileId)
.replaceQuery(null)
.build();
return downloadUri.toUriString();
}
else
{
// TODO this is a workaround for the situation where the File url needs to be created without a request
// context, in order to fix the properly we would need to add a deploy time property
// defining the file download server location
return FileDownloadController.URI + '/' + fileId;
}
}
示例3: index
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入方法依赖的package包/类
@RequestMapping(value = "/", method = RequestMethod.GET)
String index(Model model, //
@QuerydslPredicate(root = User.class) Predicate predicate, //
@PageableDefault(sort = { "lastname", "firstname" }) Pageable pageable, //
@RequestParam MultiValueMap<String, String> parameters) {
ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromCurrentRequest();
builder.replaceQueryParam("page", new Object[0]);
model.addAttribute("baseUri", builder.build().toUri());
model.addAttribute("users", repository.findAll(predicate, pageable));
return "index";
}
示例4: fromCurrentRequest
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入方法依赖的package包/类
public ServletUriComponentsBuilder fromCurrentRequest()
{
return ServletUriComponentsBuilder.fromCurrentRequest();
}
示例5: uriComponentsBuilder
import org.springframework.web.servlet.support.ServletUriComponentsBuilder; //导入方法依赖的package包/类
/**
* Construct a {@link UriComponentsBuilder} with the current http request.
*
* @return A request scope {@link UriComponentsBuilder} bean.
* @since 1.0.0
*/
@Bean
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public UriComponentsBuilder uriComponentsBuilder() {
return ServletUriComponentsBuilder.fromCurrentRequest();
}