采用junit test方式
1.配置 simple-test.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="requestMappingHandlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"></bean> <bean id="requestMappingHandlerAdapter" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"></bean> </beans>
2.Junit Test Case
package com.xxx.msa.test; import java.util.Map; import java.util.Map.Entry; import org.junit.BeforeClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.mvc.method.RequestMappingInfo; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; public class TestUrl { @Autowired private static RequestMappingHandlerAdapter handlerAdapter; @Autowired private static RequestMappingHandlerMapping handlerMapping; @BeforeClass public static void before(){ ApplicationContext ctx=new ClassPathXmlApplicationContext(new String[]{ "classpath*:config/spring/spring-main.xml", "classpath*:config/spring/springmvc/springMVC.xml" ,"classpath*:config/spring/simple-test.xml"}); handlerAdapter=(RequestMappingHandlerAdapter) ctx.getBean("requestMappingHandlerAdapter"); handlerMapping=(RequestMappingHandlerMapping) ctx.getBean("requestMappingHandlerMapping"); } @Test public void testUrls(){ Map<RequestMappingInfo, HandlerMethod> handlerMethods =handlerMapping .getHandlerMethods(); for (Entry<RequestMappingInfo, HandlerMethod> item : handlerMethods .entrySet()) { RequestMappingInfo mapping = item.getKey(); HandlerMethod method = item.getValue(); for (String urlPattern : mapping.getPatternsCondition() .getPatterns()) { System.out.println(method.getBeanType().getName() + "#" + method.getMethod().getName() + " <-- " + urlPattern); if (urlPattern.equals("some specific url")) { // add to list of matching METHODS } } } } }
3.結果
@Test public void testUrls(){ System.out.println("------------以下文本復制到符合markdown語法的編輯器中------------\r\r"); Map<RequestMappingInfo, HandlerMethod> handlerMethods =handlerMapping .getHandlerMethods(); StringBuilder sb=new StringBuilder(); sb.append("[MSA系統][1]").append("\r\n"); sb.append("| 序號 | 類名 | 方法名 | URI |說明|").append("\r\n"); sb.append("| :-----:|:----|:----|:----| :----|").append("\r\n"); int index=1; for (Entry<RequestMappingInfo, HandlerMethod> item : handlerMethods .entrySet()) { RequestMappingInfo mapping = item.getKey(); HandlerMethod method = item.getValue(); sb.append("| "); for (String urlPattern : mapping.getPatternsCondition().getPatterns()) { sb.append(index+" |").append(method.getBeanType().getSimpleName()+" |").append(method.getMethod().getName()+" |").append(urlPattern+" |"); if (urlPattern.equals("some specific url")) { // add to list of matching METHODS } index++; } sb.append("|\r\n"); } sb.append("![MSA測量系統][2]").append("\r\n\r\n"); sb.append("[1]:http://baike.baidu.com/link?url=xTbrqN9R1f3b1nayzmLNlWRIV7qP3qg3g50ig14g68kPXIrcrgymGzniaR8Ay7g9kzLkYgPeUcHR_YxgTMESHa").append("\r\n"); sb.append("[2]:http:////img12.360buyimg.com/n0/jfs/t703/314/1199846466/213652/541cad01/5527d639N36f38009.jpg").append("\r\n"); System.out.println(sb); }
markdown語法表格效果
[MSA系統][1] | 序號 | 類名 | 方法名 | URI |說明| | :-----:|:----|:----|:----| :----| | 1 |GageCheckRecordController |create |/GageCheckRecord/create || | 2 |GageCheckRecordController |update |/GageCheckRecord/update || | 3 |GageCheckRecordController |gageCheckRecordIndex |/GageCheckRecord/list || | 4 |GageCheckRecordController |gageCheckRecordExport |/GageCheckRecord/export || | 5 |GageController |delete |/Gage/delete/{gageId} || | 6 |GageController |CheckConfigUpate |/Gage/CheckConfig/update || | 7 |GageController |CheckConfigSwitch |/Gage/CheckConfigSwitch/update || | 8 |GageController |gageNew |/Gage/create || | 9 |GageController |gageUpdate |/Gage/update || | 10 |GageController |findByGageId |/Gage/{gageId} || | 11 |GageController |gageLeftList |/Gage/list || | 12 |GageController |gageIndex |/Gage/index || | 13 |GageController |gageCheckRecordExport |/Gage/export || | 14 |GrrAnalysisController |create |/GrrAnalysis/create || | 15 |GrrAnalysisController |list |/GrrAnalysis/list || | 16 |GrrAnalysisController |getResult |/GrrAnalysis/getResult || | 17 |GrrAnalysisController |getInput |/GrrAnalysis/getData || | 18 |GrrAnalysisController |saveData |/GrrAnalysis/saveData || | 19 |GrrAnalysisController |compute |/GrrAnalysis/compute || | 20 |GrrTemplateController |index |/GrrTemplate/index || | 21 |GrrTemplateController |createGrrTemplate |/GrrTemplate/create || | 22 |GrrTemplateController |deleteGrrTemplate |/GrrTemplate/delete || | 23 |GrrTemplateController |getGrrTemplate |/GrrTemplate/get || | 24 |IndexController |totest |/test || | 25 |IndexController |toindex |/toindex || | 26 |LoginController |currentCompanyAccount |/Login/currentCompanyAccount || | 27 |LoginController |login |/Login/login || | 28 |LoginController |toLogin |/Login/tologin || | 29 |LoginController |logout |/Login/logout || ![MSA測量系統][2] [1]:http://baike.baidu.com/link?url=xTbrqN9R1f3b1nayzmLNlWRIV7qP3qg3g50ig14g68kPXIrcrgymGzniaR8Ay7g9kzLkYgPeUcHR_YxgTMESHa [2]:http:////img12.360buyimg.com/n0/jfs/t703/314/1199846466/213652/541cad01/5527d639N36f38009.jpg
可以把這些東西記錄在 有道雲筆記中,也可以放在github中