列印 SpringMVC中所有的介面URL,springmvcurl

來源:互聯網
上載者:User

列印 SpringMVC中所有的介面URL,springmvcurl

採用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");    }       @Testpublic 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.結果

@Testpublic 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中

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.