何か。 まず2つの方法のマッピング3 URLの持つコントローラの書き込み:RequestMappingHandlerMapping Beanを作成し、あなたの@Configurationクラスに続いて
@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";
}
}
を:
:
@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;
}
}
は地図を反転専用コントローラを作成します。
@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";
}
}
showDocページで、新しく構築されたマップを繰り返します。
<!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>
は、これは(メソッドで注文し、マッピングされたURLの提供)次のビューを提供します:公共org.springframework.web.servlet.ModelAndViewの組織:Spring MVCのURLの
Javaメソッドの
ドキュメント。 springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(のjavax.servlet.http.HttpServletRequest、javax.servlet.http.HttpServletResponseの)、URL:[/エラー]
JAVA方法:公共のjava.lang.Stringコム。デモ.DemoController.firstMethod(org.springframework.ui.Model)、URL:[/ test]
JAVA方法:公共org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(するjavax.servlet.http.HttpServletRequest)、URL:[/エラー]
JAVAメソッド:public java.lang.String com.demo.DemoController.secondMethod(org.springframework.ui.Model)、URL:[/ test/demo || /テスト/ DEMO1]
JAVA方法:公共のjava.lang.String com.demo.RequestMappingController.showDoc(org.springframework.ui.Mode
は、あなたの質問は何である –
私は春からそれらのURLを取得できますか?マッピング? – Nikita
多分、ここで提供される答えはあなたが望むことをしていますか?https://stackoverflow.com/questions/10898056/how-to-find-all-controllers-in-spring-mvc/10899118#10899118 – lumue