有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 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