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 ...
随机推荐
- 数据库MySQL(课下作业)
一.作业要求 下载附件中的world.sql.zip, 参考http://www.cnblogs.com/rocedu/p/6371315.html#SECDB,导入world.sql,提交导入成功截 ...
- 在Coding上搭建Hexo个人博客
先注册一个Coding账号,然后创建一个项目这个项目的名字应该是{username}.coding.me 安装hexo脚手架 $ npm install -g hexo-cli 建站 安装完 Hexo ...
- 一个适合.NET Core的代码安全分析工具 - Security Code Scan
本文主要翻译自Security Code Scan的官方Github文档,结合自己的初步使用简单介绍一下这款工具,大家可以结合自己团队的情况参考使用.此外,对.NET Core开发团队来说,可以参考张 ...
- ReentrantLock是如何基于AQS实现的
ReentrantLock是一个可重入的互斥锁,基于AQS实现,它具有与使用 synchronized 方法和语句相同的一些基本行为和语义,但功能更强大. lock和unlock ReentrantL ...
- python学习第四讲,python基础语法之判断语句,循环语句
目录 python学习第四讲,python基础语法之判断语句,选择语句,循环语句 一丶判断语句 if 1.if 语法 2. if else 语法 3. if 进阶 if elif else 二丶运算符 ...
- Android 8.0 的部分坑及对应解决方法
虽然 Android 9.0 都已经面世了,本篇文章写的有点迟了. 但是迟到好过不到,因此基于此这边还是记录一下项目中遇到的 Android 8.0 的坑及对应解决方法. 每次系统升级,虽然系统功能更 ...
- AspNetCore 中使用 InentityServer4(2)
基于上一篇文章 实现对IdnetityServer4 服务的使用 1:添加接口解决方案,并且使接口受认证服务的保护: 首先在解决方案中添加Api项目如下图所示: 在API项目中添加Nuget 引用 如 ...
- socket,模拟服务器、客户端通信
服务器代码: using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;u ...
- Arrays工具、二维数组以及LeetCode练习题
1 Arrays PS:Arrays位于java.util包下 int binarySearch(type[] a, type key); 使用二分法查询 key 元素在 a 数组中的索引,如果数组不 ...
- 零基础学Python--------第9章 异常处理及程序调试
第9章 异常处理及程序调试 9.1 异常概述 在程序运行过程中,经常会遇到各种各样的错误,这些错误统称为“异常”.这些异常有的是由于开发者将关键字敲错导致的,这类错误多数产生的是SyntaxError ...