@GetMapping("/getAllUrl")
public void getAllUr(HttpServletResponse response) throws Exception {
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
List<List> sheetData = new ArrayList<>();
Set<RequestMappingInfo> requestMappingInfos = map.keySet();
for(RequestMappingInfo requestMappingInfo: requestMappingInfos) {
List<String> rowData = new ArrayList<>();
// beanName
HandlerMethod handlerMethod = map.get(requestMappingInfo);
rowData.add(handlerMethod.getBean().toString());
// 全路径
String fullClassPath = handlerMethod.getBeanType().getName();
rowData.add(fullClassPath);
// 请求地址
Set<String> patterns = requestMappingInfo.getPatternsCondition().getPatterns();
for(String url :patterns) {
rowData.add(url + " ");
}
// 请求方式
Set<RequestMethod> requestMethods = requestMappingInfo.getMethodsCondition().getMethods();
for(RequestMethod requestMethod: requestMethods) {
rowData.add(requestMethod.name() + " ");
}
sheetData.add(rowData);
}
// todo 写入excel
}
Spring boot项目获取所有请求路径
最新推荐文章于 2024-04-18 09:42:01 发布