Print all interface URLs in SpringMVC, springmvcurl
Junit test
1. Configure 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. Results
@ Testpublic void testUrls () {System. out. println ("------------ copy the following text to the editor that complies with the markdown syntax ------------ \ r"); Map <RequestMappingInfo, HandlerMethod> handlerMethods = handlerMapping. getHandlerMethods (); StringBuilder sb = new StringBuilder (); sb. append ("[MSA system] [1]"). append ("\ r \ n"); sb. append ("| Sn | class name | method name | URI | description | "). append ("\ r \ n"); sb. append ("|: -----: |: ---- | "). append ("\ r \ n"); int index = 1; f Or (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 (urlPatte Rn. equals ("some specific url") {// add to list of matching METHODS} index ++;} sb. append ("| \ r \ n");} sb. append ("! [MSA measurement system] [2] "). append (" \ r \ n "); sb. append (" [1]: http://baike.baidu.com/link? Url = response "). append ("\ r \ n"); sb. append ("[2]: http: // response "). append ("\ r \ n"); System. out. println (sb );}
Markdown syntax table Effect
[MSA system] [1] | No. | class name | method name | URI | description |: -----: |: ---- |: ---- | 1 | GageCheckRecordController | create |/GageCheckRecord/create | 2 | GageCheckRecordController | update |/GageCheckRecord/update | 3 | GageCheckRecordController | required |/GageCheckRecord/list | | 4 | GageCheckRecordController | gageCheckRecordExport |/GageCheckRecord/export | 5 | GageController | delete |/Gage/dele Te/{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 | average | compute |/Gr RAnalysis/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 | currentCompany Account |/Login/currentCompanyAccount | 27 | LoginController | login |/Login/login | 28 | LoginController | toLogin |/Login/tologin | 29 | LoginController | logout |/Login/logout |! [MSA measurement system] [2] [1]: http://baike.baidu.com/link? Url = response [2]: http: // response
These items can be recorded in youdao cloud notes, or on github.