栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring MVC获取所有请求映射

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring MVC获取所有请求映射

如果您使用的是Spring
3.1,则此handlerMapping组件是RequestMappingHandlerMapping的一个实例,您可以通过以下方式查询以找到handlerMappedMethods和关联的控制器(如果您使用的是Spring的较旧版本,则应该能够使用类似的方法):

import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;@Controllerpublic class EndpointDocController { private final RequestMappingHandlerMapping handlerMapping; @Autowired public EndpointDocController(RequestMappingHandlerMapping handlerMapping) {  this.handlerMapping = handlerMapping; } @RequestMapping(value="/endpointdoc", method=RequestMethod.GET) public void show(Model model) {  model.addAttribute("handlerMethods", this.handlerMapping.getHandlerMethods()); } }

我已在此网址http://biju-allandsundry.blogspot.com/2012/03/endpoint-documentation-
controller-for.html
上提供了更多详细信息

这基于Spring Source的Rossen Stoyanchev在Spring 3.1上的演示。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371562.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号