2014년 4월 5일 토요일

Spring 3.1에서 RequestMapping 리스트 출력하기




/********************************************************************************
EndpointDocController.java


********************************************************************************/


package com.test.spring.controller;

import java.util.Map;

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.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

@Controller
public class EndpointDocController{
@Autowired
private RequestMappingHandlerMapping requestMappingHandlerMapping;

@RequestMapping( value = "/endPoints", method = RequestMethod.GET )
public String getEndPointsInView( Model model )
{
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();
model.addAttribute( "map", map );
   return "tools/endPoints";
}
}


/********************************************************************************
endPoints.jsp
********************************************************************************/

<%@ 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="${map}" var="obj">
    <tr>
      <td>${obj}</td>
      <td>${obj.key.patternsCondition}</td>
      <td>${obj.value}</td>
    </tr>
  </c:forEach>

  </tbody>
</table>
</body>
</html>


댓글 없음:

댓글 쓰기