使用SpringBoot获取所有接口的路由
程序员文章站
2022-03-02 11:31:30
目录springboot获取所有接口的路由springboot部分路由生效springboot获取所有接口的路由@autowired webapplicationcontext applicat...
springboot获取所有接口的路由
@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); }
springboot部分路由生效
问题记录
项目新增接口"foo",始终不生效,经排查发现controller层的@requestmaping(value=“test”)统一加了基础路径"test",我新增的接口注解为@postmappinp(“test/foo),导致生成的路由为"test/test/foo”, 调用地址为"test/foo",所以报了404。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
上一篇: 华为watchGT3怎么看电量 华为watchGT3怎么充电
下一篇: Nginx缓存设置案例详解