RequestMapper
@RequestMapping(value = "/v1/getAllUrl", method = RequestMethod.POST)
public Object getAllUrl() {
RequestMappingHandlerMapping mapping = SpringContextHolder.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<>();
for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
Map<String, String> map1 = new HashMap<>();
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);
} return list;
} private String getMapper() {
String result = "";
RequestMappingHandlerMapping rmhp = SpringContextHolder.getBean(RequestMappingHandlerMapping.class);
Map<RequestMappingInfo, HandlerMethod> map = rmhp.getHandlerMethods();
for (RequestMappingInfo info : map.keySet()){
result += info.getPatternsCondition().toString();
HandlerMethod hm = map.get(info);
result += hm.getBeanType().getName();
result += getMethodParams(hm.getBeanType().getName(),hm.getMethod().getName());
result += info.getProducesCondition();
}
return result;
} private String getMethodParams(String className,String methodName){
String result="";
try{
ClassPool pool=ClassPool.getDefault();
ClassClassPath classPath = new ClassClassPath(this.getClass());
pool.insertClassPath(classPath);
CtMethod cm =pool.getMethod(className, methodName);
// 使用javaassist的反射方法获取方法的参数名
MethodInfo methodInfo = cm.getMethodInfo();
CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
result=cm.getName() + "(";
if (attr == null) {
return result + ")";
}
CtClass[] pTypes=cm.getParameterTypes();
String[] paramNames = new String[pTypes.length];
int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
for (int i = 0; i < paramNames.length; i++) {
if(!pTypes[i].getSimpleName().startsWith("HttpServletRe")){
result += pTypes[i].getSimpleName();
paramNames[i] = attr.variableName(i + pos);
result += " " + paramNames[i]+",";
}
}
if(result.endsWith(",")){
result=result.substring(0, result.length()-1);
}
result+=")";
}catch(Exception e){
e.printStackTrace();
}
return result;
}
RequestMapper的更多相关文章
- springmvc学习(二)——使用RequestMapper请求映射
本次内容是@RequestMapping,后面会有实例代码 Spring MVC 使用 @RequestMapping 注解为控制器指定可以处理哪些 URL 请求在控制器的类定义及方法定义处都可标注@ ...
- springMVC中@requestMapper的使用和注意事项
package com.hope.controller;import org.springframework.stereotype.Controller;import org.springframew ...
- 零配置简单搭建SpringMVC 项目
SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...
- 一个最小化的SpringBoot项目
项目结构 项目基于Maven管理,注意使用了父pom <parent> <groupId>org.springframework.boot</groupId> &l ...
- 使用Maven快速创建一个SpringMVC工程步骤
第一步:创建maven工程,加入SpringMVC的maven依赖: <dependency> <groupId>org.springframework</groupId ...
- 每天学点SpringMVC-异常处理
1. 第一步先写个Hello World 1.1 编写一个抛出异常的目标方法 @RequestMapping("/testException.do") public String ...
- Spring MVC 详解之废话少说
<陈翔六点半之废话少说>.... Spring WEB MVC 的请求流程: Spring WEB MVC架构: 开始创建.配置gradle项目 1.在gralde项目中,选择SDK 和框 ...
- Swagger使用指南
1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法 ...
- SSM 记录
前言:本过程从0开始,先是导入最核心的jar包,然后随着ssm中的功能实现,打包===>启动===>报错,一步步解决问题,增加额外的必须的jar包来熟悉ssm 1.导包(核心包) myba ...
随机推荐
- Arduino入门笔记(5):1602液晶实验(实现时钟)
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.Arduino板 https://item.taoba ...
- MVC详解:mvc是什么?为什么要用MVC?MVC工作原理以及MVC优缺点
一.什么是MVC Model:模型层 View:视图层 Controller:控制层 MVC (Modal View Controler)本来是存在于Desktop程序中的,M是指数据模型,V是指用户 ...
- chrome谷歌浏览器开发者工具-网络带宽控制
有时候我们想在本地测试一下图片预加载loading的加载情况,如下图: 可无奈一般网络带宽都比较好,基本上看不到效果,图片一下子就加载出来了, 可能这个时候有些小伙伴想到的办法是用定时器延迟加载 其实 ...
- 解决 HomeBrew 下载缓慢的问题
macOS 自身不提供包管理器,常用的包管理器有 HomeBrew MacPorts MacPorts 第一次使用要 build 整个基本库,编译时间很长.优点是不怎么依赖系统,更新 macOS 不会 ...
- Django+xadmin打造在线教育平台(一)
目录 在线教育平台(一) 在线教育平台(二) 在线教育平台(三) 在线教育平台(四) 在线教育平台(五) 在线教育平台(六) 在线教育平台(七) 在线教育平台( ...
- 以写作为例说下IT人如何培养挣钱DNA
洛克菲勒说:“如果把我剥得一文不名丢在沙漠的中央,只要一行驼队经过——我就可以重建整个王朝.”这话反过来可以这样说,方法不对路,也不肯干的人,哪怕给一笔财富(比如人生小目标一个亿),最好的结果是跑赢C ...
- Python爬虫入门教程 49-100 Appium安装+操作51JOB_APP(模拟手机操作之一)手机APP爬虫
爬前准备工作 在开始安装Appium之前,你要先知道Appium是做什么的?Appium 是一个自动化测试开源工具,看到没,做测试用的,它有点类似Selenium,可以自动操作APP实现一系列的操作. ...
- Linux用户和权限管理看了你就会用啦
前言 只有光头才能变强 回顾前面: 看完这篇Linux基本的操作就会了 没想到上一篇能在知乎获得千赞呀,Linux也快期末考试了,也有半个月没有写文章了.这篇主要将Linux下的用户和权限知识点再整理 ...
- Recording and playing back data
Recording and playing back data This tutorial will teach you how to record data from a running ROS s ...
- Easyui 合并单元格
onMyLoadSuccessText: function () { $(".datagrid-row").mouseover(function () { var titlestr ...