使用SpringBoot獲取所有接口的路由
SpringBoot獲取所有接口的路由
@Autowired WebApplicationContext applicationContext; @RequestMapping(value = "v1/getAllUrl", method = RequestMethod.POST) public Object getAllUrl() { RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class); // 獲取url與類和方法的對應(yīng)信息 Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); // List<String> urlList = new ArrayList<>(); // for (RequestMappingInfo info : map.keySet()) { // // 獲取url的Set集合,一個(gè)方法可能對應(yīng)多個(gè)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); }
Springboot部分路由生效
問題記錄
項(xiàng)目新增接口"foo",始終不生效,經(jīng)排查發(fā)現(xiàn)controller層的@RequestMaping(value=“test”)統(tǒng)一加了基礎(chǔ)路徑"test",我新增的接口注解為@PostMappinp(“test/foo),導(dǎo)致生成的路由為"test/test/foo”, 調(diào)用地址為"test/foo",所以報(bào)了404。
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Java實(shí)現(xiàn)作業(yè)調(diào)度的示例代碼
這篇文章主要為大家詳細(xì)介紹了如何利用Java實(shí)現(xiàn)SJF算法調(diào)度,要求測試數(shù)據(jù)可以隨即輸入或從文件中讀入,文中的示例代碼講解詳細(xì),需要的可以參考一下2023-04-04Spring?Boot?3.1中整合Spring?Security和Keycloak的方法
本文介紹在最新的SpringBoot3.1版本之下,如何將Keycloak和Spring?Security一起跑起來,文中結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧2023-06-06解決Spring?Security集成knife4j訪問接口文檔出現(xiàn)403的問題
這篇文章主要給大家介紹了如何解決Spring?Security集成knife4j訪問接口文檔出現(xiàn)403的問題,文中有詳細(xì)的解決方案,有需要的朋友可以參考閱讀下2023-07-07使用LambdaQueryWrapper動(dòng)態(tài)加過濾條件?動(dòng)態(tài)Lambda
這篇文章主要介紹了使用LambdaQueryWrapper動(dòng)態(tài)加過濾條件?動(dòng)態(tài)Lambda,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。2022-01-01Java實(shí)現(xiàn)將word轉(zhuǎn)換為html的方法示例【doc與docx格式】
這篇文章主要介紹了Java實(shí)現(xiàn)將word轉(zhuǎn)換為html的方法,結(jié)合實(shí)例形式分析了java針對doc與docx格式文件的相關(guān)轉(zhuǎn)換操作技巧,需要的朋友可以參考下2019-03-03