本文整理汇总了Java中org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder类的典型用法代码示例。如果您正苦于以下问题:Java MvcUriComponentsBuilder类的具体用法?Java MvcUriComponentsBuilder怎么用?Java MvcUriComponentsBuilder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MvcUriComponentsBuilder类属于org.springframework.web.servlet.mvc.method.annotation包,在下文中一共展示了MvcUriComponentsBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listUploadedFiles
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@GetMapping("")
public String listUploadedFiles(Model model) throws IOException {
List<String> urls = storageService
.loadAll()
.map(path ->
MvcUriComponentsBuilder
.fromMethodName(FileUploadController.class, "serveFile", path.getFileName().toString())
.build().encode().toString())
.collect(Collectors.toList());
List<String> names = storageService
.loadAll()
.map(path ->
path.getFileName().toString())
.collect(Collectors.toList());
List fileAndNames = new ArrayList<Map<String,String>>(urls.size());
for(int i=0; i<urls.size(); i++){
Map<String,String> mp = new HashMap<>();
mp.put("url",urls.get(i));
mp.put("name",names.get(i));
fileAndNames.add(mp);
}
model.addAttribute("files", fileAndNames);
return "upload/uploadForm";
}
示例2: created
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
/**
* Displays the sent message to the sender after sending.
*/
@GetMapping("/{id:[a-f0-9]{64}}")
public String created(@PathVariable("id") final String id,
@RequestParam("linkSecret") final String linkSecret,
final Model model,
final UriComponentsBuilder uriComponentsBuilder) {
final SenderMessage senderMessage = messageService.getSenderMessage(id);
final String receiveUrl = MvcUriComponentsBuilder
.fromMappingName(uriComponentsBuilder, "RC#receive")
.arg(0, senderMessage.getReceiverId())
.arg(1, linkSecret)
.build();
model
.addAttribute("receiveUrl", receiveUrl)
.addAttribute("senderMessage", senderMessage)
.addAttribute("linkSecret", linkSecret);
return FORM_MSG_STATUS;
}
示例3: getLinkDefinitions
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@Override
public List<LinkDefinition<Build>> getLinkDefinitions() {
return Arrays.asList(
LinkDefinitions.link(
"_changeLog",
build -> {
BuildDiffRequest request = new BuildDiffRequest();
request.setFrom(build.getId());
return MvcUriComponentsBuilder.on(SVNController.class).changeLog(request);
},
(build, rc) -> rc.isProjectFunctionGranted(build, ProjectView.class) &&
svnService.getSVNRepository(build.getBranch()).isPresent()
),
LinkDefinitions.page(
"_changeLogPage",
(build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) &&
svnService.getSVNRepository(build.getBranch()).isPresent(),
"extension/svn/changelog"
)
);
}
示例4: build
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@Override
public URI build(Object methodInvocation) {
// Default builder
UriComponentsBuilder builder = MvcUriComponentsBuilder.fromMethodCall(methodInvocation);
// Default URI
UriComponents uriComponents = builder.build();
// TODO #251 Workaround for SPR-12771
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
HttpRequest httpRequest = new ServletServerHttpRequest(request);
String portHeader = httpRequest.getHeaders().getFirst("X-Forwarded-Port");
if (StringUtils.hasText(portHeader)) {
int port = Integer.parseInt(portHeader);
String scheme = uriComponents.getScheme();
if (("https".equals(scheme) && port == 443) || ("http".equals(scheme) && port == 80)) {
port = -1;
}
builder.port(port);
}
// OK
return builder.build().toUri();
}
示例5: getInformation
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
/**
* Gets the list of information extensions for an entity
*/
@RequestMapping(value = "information/{entityType}/{id}", method = RequestMethod.GET)
public Resources<EntityInformation> getInformation(@PathVariable ProjectEntityType entityType, @PathVariable ID id) {
// Gets the entity
ProjectEntity entity = getEntity(entityType, id);
// List of informations to return
List<EntityInformation> informations = extensionManager.getExtensions(EntityInformationExtension.class).stream()
.map(x -> x.getInformation(entity))
.filter(Optional::isPresent)
.map(Optional::get)
.collect(Collectors.toList());
// OK
return Resources.of(
informations,
uri(MvcUriComponentsBuilder.on(getClass()).getInformation(entityType, id))
);
}
示例6: getLinkDefinitions
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@Override
public List<LinkDefinition<Build>> getLinkDefinitions() {
return Arrays.asList(
LinkDefinitions.link(
"_changeLog",
build -> MvcUriComponentsBuilder.on(GitController.class).changeLog(new BuildDiffRequest().withFrom(build.getId())),
(build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) &&
gitService.isBranchConfiguredForGit(build.getBranch())
),
LinkDefinitions.page(
"_changeLogPage",
(build, resourceContext) -> resourceContext.isProjectFunctionGranted(build, ProjectView.class) &&
gitService.isBranchConfiguredForGit(build.getBranch())
,
"extension/git/changelog"
)
);
}
示例7: createOtherTitleContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of titles")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/othertitles", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createOtherTitleContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<OtherTitle> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createOtherTitleContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getOtherTitleContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例8: createReleaseDateContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of release dates")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/releasedates", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createReleaseDateContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<ReleaseDate> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createReleaseDateContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getReleaseDateContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例9: createStorylineContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of storylines")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/storylines", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createStorylineContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Storyline> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createStorylineContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getStorylineContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例10: createBoxOfficeContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of box offices")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/boxoffices", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createBoxOfficeContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<BoxOffice> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createBoxOfficeContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getBoxOfficeContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例11: createSiteContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of sites")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/sites", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createSiteContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Site> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createSiteContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getSiteContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例12: createCountryContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of countries")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/countries", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createCountryContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Country> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createCountryContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getCountryContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例13: createLanguageContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of languages")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/languages", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createLanguageContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Language> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createLanguageContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getLanguageContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例14: createGenreContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of genres")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/genres", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createGenreContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Genre> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createGenreContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getGenreContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}
示例15: createReviewContribution
import org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder; //导入依赖的package包/类
@ApiOperation(value = "Create the contribution of reviews")
@ApiResponses(value = {
@ApiResponse(code = 400, message = "Incorrect data in the DTO"),
@ApiResponse(code = 404, message = "No movie found or no user found"),
@ApiResponse(code = 409, message = "An ID conflict or element exists"),
})
@PreAuthorize("hasRole('ROLE_USER')")
@PostMapping(value = "/{id}/contributions/reviews", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.CREATED)
public
ResponseEntity<Void> createReviewContribution(
@ApiParam(value = "The movie ID", required = true)
@PathVariable("id") final Long id,
@ApiParam(value = "The contribution", required = true)
@RequestBody @Valid final ContributionNew<Review> contribution
) {
log.info("Called with id {}, contribution {}", id, contribution);
final Long cId = this.movieContributionPersistenceService.createReviewContribution(contribution, id, this.authorizationService.getUserId());
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(
MvcUriComponentsBuilder
.fromMethodName(MovieContributionRestController.class, "getReviewContribution", cId)
.buildAndExpand(cId)
.toUri()
);
return new ResponseEntity<>(httpHeaders, HttpStatus.CREATED);
}