Endpoint documentation controller for Spring MVC 3.1
source link: http://www.java-allandsundry.com/2012/03/endpoint-documentation-controller-for.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Endpoint documentation controller for Spring MVC 3.1
I saw a demo on new Spring MVC 3.1 features by Rossen Stoyanchev a while back and found one particular demo item incredibly useful.
The demonstration was for an Endpoint Controller - a page to display all the uri's supported by the application, their corresponding handler methods and related patterns(method, params etc).
The RequestMappingHandlerMapping component of Spring MVC maps the uri's to different @RequestMapped methods, and the demo item shows a way to expose these uri's and handler methods using a controller - the Endpoint documentation Controller, which looks like this:
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller;
import
org.springframework.ui.Model;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
@Controller
public
class
EndpointDocController {
private
final
RequestMappingHandlerMapping handlerMapping;
@Autowired
public
EndpointDocController(RequestMappingHandlerMapping handlerMapping) {
this
.handlerMapping = handlerMapping;
}
@RequestMapping
(value=
"/endpointdoc"
, method=RequestMethod.GET)
public
void
show(Model model) {
model.addAttribute(
"handlerMethods"
,
this
.handlerMapping.getHandlerMethods());
}
}
<div class="container"> <div class="container"> <h1>Spring MVC 3.1 Demo Endpoints</h1> <c:forEach items="${handlerMethods}" var="entry"> <div> <hr> <p><strong>${entry.value}</strong></p> </div> <div class="span-3 colborder"> <p> <span class="alt">Patterns:</span><br> <c:if test="${not empty entry.key.patternsCondition.patterns}"> ${entry.key.patternsCondition.patterns} </c:if> </p> </div> ......
This would be something along the lines of what is displayed in the UI:
More information is available at the demo link and at Rossen Stoyanchev's github location: https://github.com/rstoyanchev/spring-mvc-31-demo.git
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK