获取SSM项目中所有的URL
2017-10-26 14:10
387 查看
1、在springmvc配置加上两个bean:
2、在controller注入RequestMappingHandlerAdapter:
3、controller添加mapping:
注:如果实例化RequestMappingHandlerMapping出错,大概是你项目不仅仅只有一个实例,此时请为你写的bean设置id
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
2、在controller注入RequestMappingHandlerAdapter:
@Autowired RequestMappingHandlerMapping requestMappingHandlerMapping;
3、controller添加mapping:
@RequestMapping("/index.action") @ResponseBody public Object index(HttpServletRequest request) { List<HashMap<String, String>> urlList = new ArrayList<HashMap<String, String>>(); Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods(); for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) { HashMap<String, String> hashMap = new HashMap<String, String>(); RequestMappingInfo info = m.getKey(); HandlerMethod method = m.getValue(); PatternsRequestCondition p = info.getPatternsCondition(); for (String url : p.getPatterns()) { hashMap.put("url", url); } hashMap.put("className", method.getMethod().getDeclaringClass().getName()); // 类名 hashMap.put("method", method.getMethod().getName()); // 方法名 RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition(); String type = methodsCondition.toString(); if (type != null && type.startsWith("[") && type.endsWith("]")) { type = type.substring(1, type.length() - 1); hashMap.put("type", type); // 方法名 } urlList.add(hashMap); } HashMap<String, Object> result = new HashMap<String, Object>(); result.put("str", urlList); return result; }
注:如果实例化RequestMappingHandlerMapping出错,大概是你项目不仅仅只有一个实例,此时请为你写的bean设置id
相关文章推荐
- 十.scrapy项目 爬取主页http://cuiqingcai.com/获取所有url与title
- django快速获取项目所有的URL
- SpringMVC项目中获取所有URL到Controller Method的映射
- django获取项目所有的URL
- [置顶] django快速获取项目所有的URL
- SpringMVC项目中获取所有URL到Controller Method的映射
- django快速获取项目所有的URL
- django快速获取项目所有的URL
- django快速获取项目所有的URL
- 项目启动时获取项目中的所有url
- 获取指定URl页面中所有链接
- C#获取远程网页中的所有链接URL
- 获取SpringMVC中所有RequestMapping映射URL地址
- 正则表达式获取url中的所有参数和值
- 完成Ueditor的上传视频功能及ajax+SSM+获取url
- 获取项目文件目录下的所有文件路径
- js获取当前项目根路径URL
- 怎样获取页面上所有链接的名称和url
- 根据WSDL的URL来获取服务中的所有方法
- JQuery获取请求url的所有参数