获取SSM项目中所有的URL
程序员文章站
2022-03-02 18:05:49
...
1、在springmvc配置加上两个bean:
<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
上一篇: flex 动态加载CSS
下一篇: css flex
推荐阅读
-
获取Django项目的全部url方法详解
-
获取Django项目的全部url方法详解
-
Layui数据表格之获取表格中所有的数据的方法
-
项目小结:手机邮箱正则,URL各种判断返回页面,input输入框输入符合却获取不到问题
-
Android项目实战(五十六):获取WebView加载的url的请求错误码
-
获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列。
-
获取一个数的二进制序列中所有的偶数位和奇数位, 分别输出其二进制序列
-
【C练】获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列。
-
获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列
-
获取一个数二进制序列中所有的偶数位和奇数位, 分别输出二进制序列。