获取项目中所有URL--获取swagger上展示的接口信息
有时我们需要接口的一些基本信息,比如接口请求路径,接口请求方式等,我们用这些信息来做判断,或者入库。
我在开发接口权限的时候就遇到了这个问题,之前写的接口很多,现在需要将这些接口信息存到数据库中,
用来做接口的权限操作,经过一番查阅,在此汇总了一下:
@Autowired
WebApplicationContext applicationContext; @RequestMapping(value = "/getAllURL", method = RequestMethod.POST)
public Object getAllURL() {
List<Map<String, String>> resultList = new ArrayList<>(); RequestMappingHandlerMapping requestMappingHandlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
// 获取url与类和方法的对应信息
Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods(); for (Map.Entry<RequestMappingInfo, HandlerMethod> mappingInfoHandlerMethodEntry : map.entrySet()) {
Map<String, String> resultMap = new LinkedHashMap<>(); RequestMappingInfo requestMappingInfo = mappingInfoHandlerMethodEntry.getKey();
HandlerMethod handlerMethod = mappingInfoHandlerMethodEntry.getValue(); resultMap.put("className",handlerMethod.getMethod().getDeclaringClass().getName()); // 类名
Annotation[] parentAnnotations = handlerMethod.getBeanType().getAnnotations();
for (Annotation annotation : parentAnnotations) {
if (annotation instanceof Api) {
Api api = (Api) annotation;
resultMap.put("classDesc",api.value());
} else if (annotation instanceof RequestMapping) {
RequestMapping requestMapping = (RequestMapping) annotation;
if (null != requestMapping.value() && requestMapping.value().length > 0) {
resultMap.put("classURL",requestMapping.value()[0]);//类URL
}
}
}
resultMap.put("methodName", handlerMethod.getMethod().getName()); // 方法名
Annotation[] annotations = handlerMethod.getMethod().getDeclaredAnnotations();
if (annotations != null) {
// 处理具体的方法信息
for (Annotation annotation : annotations) {
if (annotation instanceof ApiOperation) {
ApiOperation methodDesc = (ApiOperation) annotation;
String desc = methodDesc.value();
resultMap.put("methodDesc",desc);//接口描述
}
}
}
PatternsRequestCondition p = requestMappingInfo.getPatternsCondition();
for (String url : p.getPatterns()) {
resultMap.put("methodURL",url);//请求URL
}
RequestMethodsRequestCondition methodsCondition = requestMappingInfo.getMethodsCondition();
for (RequestMethod requestMethod : methodsCondition.getMethods()) {
resultMap.put("requestType",requestMethod.toString());//请求方式:POST/PUT/GET/DELETE
}
resultList.add(resultMap);
}
return JSONArray.fromObject(resultList);
}
获取项目中所有URL--获取swagger上展示的接口信息的更多相关文章
- Django自动获取项目中的全部URL
import re from collections import OrderedDict from django.conf import settings from django.utils.mod ...
- ASP.NET 获取来源网站的网址,获取上一网页的网址,获取来源网页的URL,获取上一网页的URL
ASP.NET 获取来源网站的网址,获取上一网页的网址,获取来源网页的URL, 获取上一网页的URL Uri Url = HttpContext.Current.Request.UrlReferrer ...
- JS 获取字符串中的url并返回其下标索引
//获取字符串中的url极其下标索引 function getHttpUrlArray(s) { var s1 = s.match(/http.*/); if(s1 == null) { return ...
- Java获取项目中的路径 分类: Java Game 2014-08-14 10:17 122人阅读 评论(0) 收藏
在项目中经常需要获取某个文件的路径: 在这里提供一些获取路径的方法.. 1.此种方式获取的路径,是当前类所在的路径: UserDAOTest.class.getResource("UserD ...
- [置顶]
django快速获取项目所有的URL
django快速获取项目所有的URL django1.10快速获取项目所有的URL列表,可以用于权限控制 函数如下: import re def get_url(urllist , parent='' ...
- django2自动发现项目中的url
根据路飞学城luffycity.com 的crm项目修改的 1 url入口:rbac/urls.py urlpatterns = [ ... # 批量操作权限 re_path(r'^multi/per ...
- 自动发现项目中的URL,django1版本和django2版本
一.django 1 版本 routers.py import re from collections import OrderedDict from django.conf import setti ...
- 自动发现项目中的url
def check_url_exclude(url): """ 判断url是否需要自动被发现,如果不是则移除 :param url: 自动发现的url :return: ...
- 项目中通过Sorlj获取索引库中的数据
在开发项目中通过使用Solr所提供的Solrj(java客户端)获取索引库中的数据,这才是真正对项目起实质性作用的功能,提升平台的检索性能及检索结果的精确性 第一步,引入相关依赖的jar包 第二步,根 ...
随机推荐
- CentOS7安装JDK1.8图文教程
https://blog.csdn.net/weixin_42266606/article/details/80863781 1.下载 jdk 的 tar 包 网址:http://www.oracle ...
- 系统树图 | Dendrogram construction | Phylogenetic Analysis
Molecular Architecture of the Mouse Nervous System 表示亲缘关系的树状图解 先看文章里是怎么做的: Dendrogram construction A ...
- js控制input框只能输入数字和一位小数点和小数点后面两位小数
<script language="JavaScript" type="text/javascript"> function clearNoNum( ...
- linux设置sudo不要密码
linux下,普通用户,sudo时需要密码 改成没密码, vi /etc/sudoers 在 root ALL=(ALL) ALL后加一行 sysusr ALL=(ALL) NOPASSWD: ALL ...
- Conv2d常设置参数意义-继续扩展
记录下一些常用设置: 1.下采样 当设置为: nn.Conv2d(nc,ndf,,,,bias=False) kernel_size = 4, stride = 2, padding = 1,就是将特 ...
- IDEA中MyBatis插件的安装及使用
这个插件的好处就在于能自动关联mapper类与xml,让你可以快速的互相跳转,还能帮助你做简单的排错. 安装方法: 1.File→Settings→Plugins,输入mybatis plugin,本 ...
- AC与AP的安装使用(未经实战,仅供参考,未完待续)
AC:无线控制器(Wireless Access Point Controller) AP:无线访问接入点(WirelessAccessPoint) 以信锐AC为例 AC设备的管理口为MANAGE(E ...
- close yarn install --check-files
To disable this check, please add `config.webpacker.check_yarn_integrity = false` to your Rails deve ...
- Python微服务实践-集成Consul配置中心
A litmus test for whether an app has all config correctly factored out of the code is whether the co ...
- mysql 控制流函数
MySQL有4个函数是用来进行条件操作的,这些函数可以实现SQL的条件逻辑,允许开发者将一些应用程序业务逻辑转换到数据库后台. MySQL控制流函数: CASE WHEN[test1] THEN [r ...