Skip to content

Add controller mapping relative UriComponentsBuilder [SPR-16910] #21449

@spring-projects-issues

Description

@spring-projects-issues

Michael Osipov opened SPR-16910 and commented

Consider the following snippet:

 

import java.io.InputStream;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;

@RestController
@RequestMapping("/rest/documents")
public class DocumentsController {

	@PostMapping(consumes = "application/zip")
	public ResponseEntity<?> createDocument(InputStream is, UriComponentsBuilder uriBuilder) {

		UriComponents uc = uriBuilder.path("/rest/documents/{id}").buildAndExpand("6667f88a-5783-11e8-857e-001f29e7988e");

		return ResponseEntity.created(uc.toUri()).build();
	}

}

Unfortunately, I have to duplicate /rest/documents with the UriComponentsBuilder. It'd be nice if this components could be controller mapping relative. I'd like to do uriBuilder.path("/{id}").buildAndExpand("6667f88a-5783-11e8-857e-001f29e7988e") only.


Affects: 5.0.6

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions