In Spring, is there a way I can find a route by name?

user3429660 :

Is there a way I can find a route by name? I am using the latest spring-boot.

Given:

@GetMapping(value = "/list", name = "list")
public String list() { ... }

I would like to be able to run something like:

route = getRouteByName("list")

I develop a Thymeleaf tag processor and I want to be able to create the URL in . It would be quite handy to use "name" parameter of @Route. I try to make the tag look like: Text

Madhu Bhat :

If you intend to build a url out of the name of the mapping, you can do it using the fromMappingName(String mappingName) method of MvcUriComponentsBuilder. Documentation of the same here.

String url = MvcUriComponentsBuilder.fromMappingName("list").build();

PS: You might need some more configurations in the builder to form your complete url though. The above example is just to ensure brevity.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=132177&siteId=1