打印spring boot的controller里定义的路由
来源:互联网 发布:电信网络宽带 编辑:程序博客网 时间:2024/05/27 00:47
简介
controller类里的方法前@RequestMapping注释的路由信息获取,如下图所示相关代码
RouteList.java
package com.ffan.util;import org.springframework.beans.factory.config.BeanDefinition;import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;import org.springframework.core.type.filter.AnnotationTypeFilter;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import java.util.Arrays;import java.util.Set;public class RouteList { public static void main(String[] args) throws ClassNotFoundException { ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(false); scanner.addIncludeFilter(new AnnotationTypeFilter(Controller.class)); Set<BeanDefinition> beanSet = scanner.findCandidateComponents("com.ffan.smartlife.controller"); for (BeanDefinition def : beanSet) { Class<?> clazz = Class.forName(def.getBeanClassName()); Arrays.stream(clazz.getDeclaredMethods()).map(m -> m.getAnnotation(RequestMapping.class)).filter( a -> a != null && a.value().length > 0).forEach( a -> Arrays.stream(a.value()).forEach( p -> { System.out.println(p); } )); } }}
效果图
设计要点
- 通过ClassPathScanningCandidateComponentProvider获取spring boot框架的元数据
- 获取controller信息
- 获取controller里的注解RequestMapping信息
参考链接
https://qiita.com/shigeshibu44/items/886efb44c8c573c3ba6b查看原文:http://www.huuinn.com/archives/195
更多技术干货:风匀坊
关注公众号:风匀坊
阅读全文
0 0
- 打印spring boot的controller里定义的路由
- spring boot项目出现controller的路由没被注册
- Spring Boot 的控制器--Controller
- 在控制台里打印controller的层级
- Spring-boot 配置Aop获取controller里的request中的参数以及其返回值
- Spring-boot 配置Aop获取controller里的request中的参数以及其返回值
- Spring Boot-Controller控制器的使用
- spring boot 所有的Controller异常捕获
- spring boot 扫描不到自定义的Controller。。。
- 控制台里打印view的层级 在控制台里打印controller的层级 及其他技巧
- spring boot的Bean,Controller以及Repository的创建
- spring boot 处理请求的方式 Controller 与RestController
- 《spring-boot学习》-12-@controller和@RestController的区别?
- Spring Boot中@Controller和@restController的区别
- spring boot 自定义controller不能扫描到的问题
- Spring Boot 学习——Controller的使用
- Spring Boot学习(一)之Controller的使用
- Spring Boot的Controller控制层和页面
- Excel 单元格中插入图片
- 单链表排序(冒泡排序)
- Android 网络层学习
- http请求详细讲解
- 廖雪峰python中filter过滤非回数
- 打印spring boot的controller里定义的路由
- kotlin学习笔记——委托属性
- Spring思维导图,让Spring不再难懂(aop篇)
- zTree树形插件使用 异步加载方法,Struts2框架
- SpringSecurity 学习记录(一)- SpringSecurity 主要的实现类
- 合并两个有序链表,合并后依然有序
- JAVA-电子签名范例代码
- 【课件】自然数的拆分问题
- Canvas