Search code examples
springspring-mvcurlparse

Reusing Spring RequestMapping parsing functionality


I have some properties like /my/{custom}/url

I would need to replace {custom} with some value at runtime

I know that Spring is using "@RequestMapping" with a similar syntax for @PathAttribute matching.

I'm wondering if there is some Class I can reuse from Spring to achieve what I need.


Solution

  • A good option for this is to use a UriComponentsBuilder - see reference here: http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/util/UriComponentsBuilder.html

    UriComponentsBuilder.fromPath("/test/{one}/{two}").buildAndExpand(map).toUriString()