Spring에서 RequestMapping 전체 목록 화면에 출력 하기
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Description; import org.springframework.core.MethodParameter; 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; import com.xcurenet.annotations.AuditMenu; import com.xcurenet.annotations.AuditOperation; import com.xcurenet.common.util.Common; @Controller public class EndpointDocController { @Autowired private RequestMappingHandlerMapping requestMappingHandlerMapping; @RequestMapping(value = "/endPoints") public String getEndPointsInView(Model model) { List<Map<String, String>> pages = new ArrayList<Map<String, String>>(); List<Map<String, String>> result = new ArrayList<Map<String, String>>(); Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods(); for (Entry<RequestMappingInfo, HandlerMethod> elem : map.entrySet()) { RequestMappingInfo key = elem.getKey(); HandlerMethod method = elem.getValue(); Map<String, String> item = new HashMap<String, String>(); item.put("path", Common.nvl(key.getPatternsCondition().getPatterns().toArray()[0])); item.put("cls", method.getMethod().getDeclaringClass().getSimpleName()); item.put("method", method.getMethod().getName()); AuditMenu auditMenu = method.getMethod().getDeclaringClass().getAnnotation(AuditMenu.class); if (auditMenu != null) { item.put("menuId", auditMenu.value().getMenuId()); } AuditOperation operation = method.getMethodAnnotation(AuditOperation.class); if (operation != null) { item.put("operation", operation.value().getOperation()); } Description desc = method.getMethodAnnotation(Description.class); if (desc != null) { item.put("desc", desc.value()); } StringBuffer sb = new StringBuffer(); for (MethodParameter param : method.getMethodParameters()) { sb.append(param.getParameterType().getSimpleName()).append(", "); } if (sb.toString().length() > 0) { item.put("param", sb.toString().substring(0, sb.toString().length() - 2)); } else { item.put("param", ""); } item.put("rtn", Common.nvl(method.getMethod().getReturnType().getSimpleName())); if (Common.isEquals(item.get("rtn"), "XcnResponseVO")) { result.add(item); } else { pages.add(item); } } model.addAttribute("endPoints", result); model.addAttribute("pages", pages); return "/endPoints"; } } |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" session="false"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <html> <head> <title>Endpoint list</title> <style type="text/css"> .tbl_list { border-top: 2px solid #73abd1; } .tbl_list table { table-layout: fixed; word-break: break-all; border-collapse: collapse; border-spacing: 0px; } .tbl_list table thead td,th { background-color: #e8f3f9; border-bottom: 1px #d7d7d7 solid; border-right: 1px #d7d7d7 solid; height: 30px; color: #2a2a2a; font-family: dotum, Verdana, arial, sans-serif; text-align: center; font-size: 12px; font-weight: bold; border-collapse: collapse; border-spacing: 0px; } .tbl_list table thead td:last-child { border-right: 0px; } .tbl_list table tbody td { padding-left: 10px; padding-right: 10px; border-bottom: 1px #d7d7d7 solid; border-right: 1px #d7d7d7 solid; height: 30px; color: #2a2a2a; font-family: dotum, Verdana, arial, sans-serif; font-size: 12px; font-weight: none; border-collapse: collapse; border-spacing: 0px; } .tbl_list table tbody td:last-child { border-right: 0px; } </style> </head> <body> <h1>Request Pages Table</h1> <div class="tbl_list"> <table> <thead> <tr> <th>Desc</th> <th>Path</th> <th>Class</th> <th>Method</th> <th>Param</th> <th>Return</th> </tr> </thead> <tbody> <c:forEach items="${pages}" var="endPoint"> <tr> <td>${endPoint.desc}</td> <td>${endPoint.path}</td> <td>${endPoint.cls}</td> <td>${endPoint.method}</td> <td>${endPoint.param}</td> <td>${endPoint.rtn}</td> </tr> </c:forEach> </tbody> </table> </div> <h1>Request Mapping Table</h1> <div class="tbl_list"> <table> <thead> <tr> <th>Desc</th> <th>Operation</th> <th>Path</th> <th>Class</th> <th>Method</th> <th>Param</th> <th>Return</th> </tr> </thead> <tbody> <c:forEach items="${endPoints}" var="endPoint"> <tr> <td>${endPoint.desc}</td> <td>${endPoint.operation}</td> <td>${endPoint.path}</td> <td>${endPoint.cls}</td> <td>${endPoint.method}</td> <td>${endPoint.param}</td> <td>${endPoint.rtn}</td> </tr> </c:forEach> </tbody> </table> </div> </body> </html> |