1. @RequestMapping(value = "/v1/getAllUrl", method = RequestMethod.POST)
  2. public Object getAllUrl() {
  3. RequestMappingHandlerMapping mapping = SpringContextHolder.getBean(RequestMappingHandlerMapping.class);
  4. // 获取url与类和方法的对应信息
  5. Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
  6.  
  7. List<String> urlList = new ArrayList<>();
  8. for (RequestMappingInfo info : map.keySet()) {
  9. // 获取url的Set集合,一个方法可能对应多个url
  10. Set<String> patterns = info.getPatternsCondition().getPatterns();
  11.  
  12. for (String url : patterns) {
  13. urlList.add(url);
  14. }
  15. }
  16.  
  17. List<Map<String, String>> list = new ArrayList<>();
  18. for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
  19. Map<String, String> map1 = new HashMap<>();
  20. RequestMappingInfo info = m.getKey();
  21. HandlerMethod method = m.getValue();
  22. PatternsRequestCondition p = info.getPatternsCondition();
  23. for (String url : p.getPatterns()) {
  24. map1.put("url", url);
  25. }
  26. map1.put("className", method.getMethod().getDeclaringClass().getName()); // 类名
  27. map1.put("method", method.getMethod().getName()); // 方法名
  28. RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
  29. for (RequestMethod requestMethod : methodsCondition.getMethods()) {
  30. map1.put("type", requestMethod.toString());
  31. }
  32. list.add(map1);
  33. }
  34.  
  35. return list;
  36. }
  37.  
  38. private String getMapper() {
  39. String result = "";
  40. RequestMappingHandlerMapping rmhp = SpringContextHolder.getBean(RequestMappingHandlerMapping.class);
  41. Map<RequestMappingInfo, HandlerMethod> map = rmhp.getHandlerMethods();
  42. for (RequestMappingInfo info : map.keySet()){
  43. result += info.getPatternsCondition().toString();
  44. HandlerMethod hm = map.get(info);
  45. result += hm.getBeanType().getName();
  46. result += getMethodParams(hm.getBeanType().getName(),hm.getMethod().getName());
  47. result += info.getProducesCondition();
  48. }
  49. return result;
  50. }
  51.  
  52. private String getMethodParams(String className,String methodName){
  53. String result="";
  54. try{
  55. ClassPool pool=ClassPool.getDefault();
  56. ClassClassPath classPath = new ClassClassPath(this.getClass());
  57. pool.insertClassPath(classPath);
  58. CtMethod cm =pool.getMethod(className, methodName);
  59. // 使用javaassist的反射方法获取方法的参数名
  60. MethodInfo methodInfo = cm.getMethodInfo();
  61. CodeAttribute codeAttribute = methodInfo.getCodeAttribute();
  62. LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);
  63. result=cm.getName() + "(";
  64. if (attr == null) {
  65. return result + ")";
  66. }
  67. CtClass[] pTypes=cm.getParameterTypes();
  68. String[] paramNames = new String[pTypes.length];
  69. int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;
  70. for (int i = 0; i < paramNames.length; i++) {
  71. if(!pTypes[i].getSimpleName().startsWith("HttpServletRe")){
  72. result += pTypes[i].getSimpleName();
  73. paramNames[i] = attr.variableName(i + pos);
  74. result += " " + paramNames[i]+",";
  75. }
  76. }
  77. if(result.endsWith(",")){
  78. result=result.substring(0, result.length()-1);
  79. }
  80. result+=")";
  81. }catch(Exception e){
  82. e.printStackTrace();
  83. }
  84. return result;
  85. }

RequestMapper的更多相关文章

  1. springmvc学习(二)——使用RequestMapper请求映射

    本次内容是@RequestMapping,后面会有实例代码 Spring MVC 使用 @RequestMapping 注解为控制器指定可以处理哪些 URL 请求在控制器的类定义及方法定义处都可标注@ ...

  2. springMVC中@requestMapper的使用和注意事项

    package com.hope.controller;import org.springframework.stereotype.Controller;import org.springframew ...

  3. 零配置简单搭建SpringMVC 项目

    SpringMVC是比较常用的JavaWeb框架,非常轻便强悍,能简化Web开发,大大提高开发效率,在各种Web程序中广泛应用.本文采用Java Config的方式搭建SpringMVC项目,并对Sp ...

  4. 一个最小化的SpringBoot项目

    项目结构 项目基于Maven管理,注意使用了父pom <parent> <groupId>org.springframework.boot</groupId> &l ...

  5. 使用Maven快速创建一个SpringMVC工程步骤

    第一步:创建maven工程,加入SpringMVC的maven依赖: <dependency> <groupId>org.springframework</groupId ...

  6. 每天学点SpringMVC-异常处理

    1. 第一步先写个Hello World 1.1 编写一个抛出异常的目标方法 @RequestMapping("/testException.do") public String ...

  7. Spring MVC 详解之废话少说

    <陈翔六点半之废话少说>.... Spring WEB MVC 的请求流程: Spring WEB MVC架构: 开始创建.配置gradle项目 1.在gralde项目中,选择SDK 和框 ...

  8. Swagger使用指南

    1:认识Swagger Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件的方法 ...

  9. SSM 记录

    前言:本过程从0开始,先是导入最核心的jar包,然后随着ssm中的功能实现,打包===>启动===>报错,一步步解决问题,增加额外的必须的jar包来熟悉ssm 1.导包(核心包) myba ...

随机推荐

  1. [AI分享]零高数理解人工智能和深度学习

  2. Hadoop系列006-HDFS概念及命令行操作

    本人微信公众号,欢迎扫码关注! HDFS概念及命令行操作 一.HDFS概念 1.1 概念 HDFS,它是一个文件系统,用于存储文件,通过目录树来定位文件:其次,它是分布式的,由很多服务器联合起来实现其 ...

  3. height:auto 火狐没边框

    css高度设置为auto后,设置的边框 ie正常 火狐 就没有边框了,解决方法 之前是这样写的 #right_bottom { width: 790px; height:auto; border: # ...

  4. 《深入理解Java虚拟机》-----第8章 虚拟机字节码执行引擎——Java高级开发必须懂的

    概述 执行引擎是Java虚拟机最核心的组成部分之一.“虚拟机”是一个相对于“物理机”的概念 ,这两种机器都有代码执行能力,其区别是物理机的执行引擎是直接建立在处理器.硬件.指令集和操作系统层面上的,而 ...

  5. Python3中性能测试工具Locust安装使用

    Locust安装使用: 安装: python3中           ---> pip3 install locust 验证是否安装成功---> 终端中输入 locust --help  ...

  6. dev Gridcontrol控件属性部分

    XtraGrid的关键类就是:GridControl和GridView.GridControl本身不显示数据,数据都是显示在GridView/CardView/XXXXView中.GridContro ...

  7. JVM(六)为什么新生代有两个Survivor分区?

    本文会使用排除法的手段,来讲解新生代的区域划分,从而让读者能够更清晰的理解分代回收器的原理,在开始之前我们先来整体认识一下分代收集器. 分代收集器会把内存空间分为:老生代和新生代两个区域,而新生代又会 ...

  8. 剑指 offer 第一题: 二维数组中的查找

    打算写 图解剑指 offer 66 题 的系列文章,不知道大家有没有兴趣

  9. 【转载】SQL语句将一个表的数据写入到另一个表中

    在日常的数据库运维过程中,有时候需要将Select查询出来的数据集写入到另一个数据表中,其中一种方式是通过存储过程循环写入数据,另一种简便的方式是直接使用Insert Into语句后面跟上Select ...

  10. 从零开始学安全(四十六)●sqli-labs 1-4关 涉及的知识点

    Less-1 到Less-4  基础知识注入 我们可以在 http://127.0.0.1/sqllib/Less-1/?id=1 后面直接添加一个 ‘ ,来看一下效果: 从上述错误当中,我们可以看到 ...