SpringBoot获取所有接口的路由
2024-10-18 09:12:10
@Autowired
WebApplicationContext applicationContext; @RequestMapping(value = "v1/getAllUrl", method = RequestMethod.POST)
public Object getAllUrl() {
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
// 获取url与类和方法的对应信息
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); // List<String> urlList = new ArrayList<>();
// for (RequestMappingInfo info : map.keySet()) {
// // 获取url的Set集合,一个方法可能对应多个url
// Set<String> patterns = info.getPatternsCondition().getPatterns();
//
// for (String url : patterns) {
// urlList.add(url);
// }
// } List<Map<String, String>> list = new ArrayList<Map<String, String>>();
for (Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
Map<String, String> map1 = new HashMap<String, String>();
RequestMappingInfo info = m.getKey();
HandlerMethod method = m.getValue();
PatternsRequestCondition p = info.getPatternsCondition();
for (String url : p.getPatterns()) {
map1.put("url", url);
}
map1.put("className", method.getMethod().getDeclaringClass().getName()); // 类名
map1.put("method", method.getMethod().getName()); // 方法名
RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
for (RequestMethod requestMethod : methodsCondition.getMethods()) {
map1.put("type", requestMethod.toString());
} list.add(map1);
}
最新文章
- Python写各大聊天系统的屏蔽脏话功能原理
- UDP Server
- Linux练习
- Gradle的安装与配置
- fastjson对Date的处理
- asp.net中水印的实现代码
- js切换换class
- CodeForces 591B
- easyui tree 的数据格式转换
- Android okHttp网络请求库详解
- Window10上安装Redis及其客户端
- Oracle通过Navicat导入表数据与机构,数据无法直接查询,需要加双引号的问题
- 【原创】大数据基础之Ambari(1)简介、编译安装、使用
- BZOJ3996[TJOI2015]线性代数——最小割
- 「About Blockchain(一)」达沃斯年会上的区块链
- Thinkphp 中的自动验证 上一篇有例子
- Django 正向解析与反向解析
- ckeditor富文本编辑器的基本配置设置:
- Redis管道传输
- Luogu 3245 大数