Something like this maybe.
First write a controller with 2 methods mapping 3 URL's:
@Controller
@RequestMapping("/test")
public class DemoController {
@RequestMapping(method = RequestMethod.GET)
public String firstMethod(Model model) {
model.addAttribute("name", "Olivier");
return "firstPage";
}
@RequestMapping(method = RequestMethod.GET, value = {"/demo", "/demo1"})
public String secondMethod(Model model) {
model.addAttribute("name", "Olivier");
return "secondPage";
}
}
Then in your @Configuration class, create the RequestMappingHandlerMapping bean:
@Configuration
public class DemoSpringApplication {
public static void main(String[] args) {
SpringApplication.run(DemoSpringApplication.class, args);
}
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = new RequestMappingHandlerMapping();
return mapping;
}
}
Create a special controller that inverts the Map:
@Controller
@RequestMapping("/requests")
public class RequestMappingController {
@Autowired
private RequestMappingHandlerMapping handler;
@RequestMapping(method = RequestMethod.GET)
public String showDoc(Model model) {
model.addAttribute("methods", handler.getHandlerMethods());
Map<RequestMappingInfo, HandlerMethod> map = handler.getHandlerMethods();
Set<RequestMappingInfo> mappings = map.keySet();
Map<String, String> reversedMap = new HashMap<String, String>();
for(RequestMappingInfo info : mappings) {
HandlerMethod method = map.get(info);
reversedMap.put(method.toString(), info.getPatternsCondition().toString());
}
model.addAttribute("methods", reversedMap);
return "showDoc";
}
}
In the showDoc page, iterate through the newly constructed map:
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>Documentation of Spring MVC URL's</h1>
<p th:each="methods: ${methods}">
<p><span th:text="'JAVA method:' + ${methods.key} + ', URL:' + ${methods.value}"></span></p>
</p>
</body>
</html>
This will give the following view (ordered by method and provides the mapped URL's):
Documentation of Spring MVC URL's
JAVA method:public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse), URL:[/error]
JAVA method:public java.lang.String com.demo.DemoController.firstMethod(org.springframework.ui.Model), URL:[/test]
JAVA method:public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest), URL:[/error]
JAVA method:public java.lang.String com.demo.DemoController.secondMethod(org.springframework.ui.Model), URL:[/test/demo || /test/demo1]
JAVA method:public java.lang.String com.demo.RequestMappingController.showDoc(org.springframework.ui.Mode