import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.AbstractHandlerMethodMapping;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import java.util.*;
@Controller
@RequestMapping(value ="/test")
public class SpringBootTest {
@Autowired
ApplicationContext applicationContext;
@RequestMapping(value = "/getPath")
public @ResponseBody List getPath(){
List<String> list=new ArrayList<>();
AbstractHandlerMethodMapping<RequestMappingInfo> objHandlerMethodMapping =
(AbstractHandlerMethodMapping<RequestMappingInfo>) applicationContext.getBean("requestMappingHandlerMapping");
Map<RequestMappingInfo,HandlerMethod> mapRet = objHandlerMethodMapping.getHandlerMethods();
for (RequestMappingInfo requestMappingInfo :mapRet.keySet()){
Set set = requestMappingInfo.getPatternsCondition().getPatterns();
Iterator iterator = set.iterator();
while (iterator.hasNext()){
list.add(iterator.next().toString());
}
}
return list;
}
}
获取本工程中有哪些请求路径
最新推荐文章于 2022-12-17 22:37:46 发布