2012-03-19 15 views
15

Hiçbir standart Spring MVC projem yok. XML'lerle yanıt verme. Kabul edilen tüm denetleyicileri, eşleştirmeleri ve parametreleri (gerekli ve değil) gösteren bir görünüm (jsp sayfası) oluşturmak mümkün mü?Tüm denetleyicileri ve eşlemeleri bir görünümde nasıl gösterilir

cevap dayanarak, var:

@RequestMapping(value= "/endpoints", params="secure", method = RequestMethod.GET) 
public @ResponseBody 
String getEndPointsInView() { 
    String result = ""; 
    for (RequestMappingInfo element : requestMappingHandlerMapping.getHandlerMethods().keySet()) { 

     result += "<p>" + element.getPatternsCondition() + "<br>"; 
     result += element.getMethodsCondition() + "<br>"; 
     result += element.getParamsCondition() + "<br>"; 
     result += element.getConsumesCondition() + "<br>"; 
    } 
    return result; 
} 

Ben Bahar 3.1 RequestMappingHandlerMapping ile @RequestParam

cevap

26

herhangi bir bilgi alamadım, kolayca son noktalarını göz atabilirsiniz.

kontrolör:

@Autowire 
private RequestMappingHandlerMapping requestMappingHandlerMapping; 

@RequestMapping(value = "endPoints", method = RequestMethod.GET) 
public String getEndPointsInView(Model model) 
{ 
    model.addAttribute("endPoints", requestMappingHandlerMapping.getHandlerMethods().keySet()); 
    return "admin/endPoints"; 
} 

görünüm:

<%@ page session="false" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> 

<html> 
<head><title>Endpoint list</title></head> 
<body> 
<table> 
    <thead> 
    <tr> 
    <th>path</th> 
    <th>methods</th> 
    <th>consumes</th> 
    <th>produces</th> 
    <th>params</th> 
    <th>headers</th> 
    <th>custom</th> 
    </tr> 
    </thead> 
    <tbody> 
    <c:forEach items="${endPoints}" var="endPoint"> 
    <tr> 
     <td>${endPoint.patternsCondition}</td> 
     <td>${endPoint.methodsCondition}</td> 
     <td>${endPoint.consumesCondition}</td> 
     <td>${endPoint.producesCondition}</td> 
     <td>${endPoint.paramsCondition}</td> 
     <td>${endPoint.headersCondition}</td> 
     <td>${empty endPoint.customCondition ? "none" : endPoint.customCondition}</td> 
    </tr> 
    </c:forEach> 
    </tbody> 
</table> 
</body> 
</html> 

Ayrıca DefaultAnnotationHandlerMapping yerine RequestMappingHandlerMapping ile, Bahar < 3.1 ile yapabilirsiniz. Ama aynı bilgi seviyesine sahip olmayacaksın.

DefaultAnnotationHandlerMapping ile sadece

+0

Ancak, ben tüm bilgileri güzel alamadım edilir ... parametreler, tüketir, kendi yöntemleri hakkında bilgi olmadan, bitiş noktaları yolunu olacaktır.

 \t @RequestMapping("/get") \t public @ResponseBody \t String getUsername( \t \t \t @RequestParam(value = "id", required = true) int id) { \t \t \t \t return "test"; \t }
mamruoc

+0

getPatternsCondition çalışıyor, ancak diğerleri çalışmıyor. – mamruoc

+0

Bu kodu kendi kullanımım için yazdım ve iyi çalışıyor. Bunun nedeni, $ {endPoint.methodsCondition} 'ın çalışmadığı hiçbir şey göstermemesidir. Bunun nedeni, endpoint için herhangi bir yöntem koşulunuz olmamasıdır. Ayrıca, 'RequestMappingHandlerMapping' bilgileri sadece 'RequestMapping' açıklama metnine dayanmaktadır. Eğer 'id' parametresini görmek istiyorsanız, bir parametre koşulu almış olmanız gerekir: '@RequestParam (value ="/get ", params = {" id "})' – tbruyelle

İlgili konular