你的位置:首页 > Java教程

[Java教程]打印 SpringMVC中所有的接口URL

采用junit test方式

1.配置  simple-test. 

<?

 

 

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.ClassPath

 

 

 

3.结果

image

 

 

 

4.延伸: 打印出符合markdown语法的表格

改写testUrl()

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

image