java如何在springmvc中从控制器名称+操作名称获取映射URL? 8 月 Questions & Answers 3223 在SpringMVC3中是否存在可以从中获取映射URL(控制器名称、操作名称)的现有解决方案,如asp中的UrlHelper。NETMVC还是rails?我认为它非常有用 thx
# 1 楼答案 也许,你想要这样的东西: 在@Controller类中,可以向“action”方法中添加 HttpServletRequest类型的额外参数 例如: @Controller public class HelloWorldController { @RequestMapping("/helloWorld") public void helloWorld(HttpServletRequest request) { //do call #getRequestURI(), or #getRequestURL(), or #getPathInfo() } } 使用默认配置,Spring将“自动”注入请求,然后您可以通过调用HttpServletRequest#getPathInfo(), HttpServletRequest#getRequestUrl()方法之一来提取路径信息(请参见此处的说明:http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#method_summary)
# 1 楼答案
也许,你想要这样的东西:
在
@Controller
类中,可以向“action”方法中添加HttpServletRequest
类型的额外参数例如:
使用默认配置,Spring将“自动”注入请求,然后您可以通过调用
HttpServletRequest#getPathInfo(), HttpServletRequest#getRequestUrl()
方法之一来提取路径信息(请参见此处的说明:http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#method_summary)