chenlimj
2012-11-27 15:31 阅读 577
已采纳

spring MVC 根据URL获取Controller

spring MVC 可以根据URL获取所有匹配的Controller吗?

 

如:/hello --> ***.HelloController

 

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    jinnianshilongnian jinnianshilongnian 2012-11-27 15:45

    AbstractUrlHandlerMapping

    lookupHandler

    protected Object lookupHandler(String urlPath,
    HttpServletRequest request)
    throws Exception
    Look up a handler instance for the given URL path.
    Supports direct matches, e.g. a registered "/test" matches "/test", and various Ant-style pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the AntPathMatcher class.

    Looks for the most exact pattern, where most exact is defined as the longest path pattern.

    Parameters:
    urlPath - URL the bean is mapped to
    request - current HTTP request (to expose the path within the mapping to)
    Returns:
    the associated handler instance, or null if not found
    Throws:
    Exception

    getHandlerMap

    public final Map getHandlerMap()
    Return the registered handlers as an unmodifiable Map, with the registered path as key and the handler object (or handler bean name in case of a lazy-init handler) as value.
    See Also:
    AbstractHandlerMapping.getDefaultHandler()

    点赞 评论 复制链接分享

相关推荐