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 ...
随机推荐
- [AI分享]零高数理解人工智能和深度学习
- Hadoop系列006-HDFS概念及命令行操作
本人微信公众号,欢迎扫码关注! HDFS概念及命令行操作 一.HDFS概念 1.1 概念 HDFS,它是一个文件系统,用于存储文件,通过目录树来定位文件:其次,它是分布式的,由很多服务器联合起来实现其 ...
- height:auto 火狐没边框
css高度设置为auto后,设置的边框 ie正常 火狐 就没有边框了,解决方法 之前是这样写的 #right_bottom { width: 790px; height:auto; border: # ...
- 《深入理解Java虚拟机》-----第8章 虚拟机字节码执行引擎——Java高级开发必须懂的
概述 执行引擎是Java虚拟机最核心的组成部分之一.“虚拟机”是一个相对于“物理机”的概念 ,这两种机器都有代码执行能力,其区别是物理机的执行引擎是直接建立在处理器.硬件.指令集和操作系统层面上的,而 ...
- Python3中性能测试工具Locust安装使用
Locust安装使用: 安装: python3中 ---> pip3 install locust 验证是否安装成功---> 终端中输入 locust --help ...
- dev Gridcontrol控件属性部分
XtraGrid的关键类就是:GridControl和GridView.GridControl本身不显示数据,数据都是显示在GridView/CardView/XXXXView中.GridContro ...
- JVM(六)为什么新生代有两个Survivor分区?
本文会使用排除法的手段,来讲解新生代的区域划分,从而让读者能够更清晰的理解分代回收器的原理,在开始之前我们先来整体认识一下分代收集器. 分代收集器会把内存空间分为:老生代和新生代两个区域,而新生代又会 ...
- 剑指 offer 第一题: 二维数组中的查找
打算写 图解剑指 offer 66 题 的系列文章,不知道大家有没有兴趣
- 【转载】SQL语句将一个表的数据写入到另一个表中
在日常的数据库运维过程中,有时候需要将Select查询出来的数据集写入到另一个数据表中,其中一种方式是通过存储过程循环写入数据,另一种简便的方式是直接使用Insert Into语句后面跟上Select ...
- 从零开始学安全(四十六)●sqli-labs 1-4关 涉及的知识点
Less-1 到Less-4 基础知识注入 我们可以在 http://127.0.0.1/sqllib/Less-1/?id=1 后面直接添加一个 ‘ ,来看一下效果: 从上述错误当中,我们可以看到 ...