在如下示例中,@PathVariable
和 @RequestParam
之间有什么区别?
@RequestMapping(value = "/portfolio/{portfolioIdPath}", method = RequestMethod.GET)
public final String portfolio(HttpServletRequest request, ModelMap model,
@PathVariable long portfolioIdPath, @RequestParam long portfolioIdRequest)
最佳答案
@RequestParam 将请求参数绑定(bind)到您方法中的参数。在您的示例中,GET 请求中名为“portfolioIdRequest”的参数的值将作为“portfolioIdRequest”参数传递给您的方法。一个更具体的例子——如果请求 URL 是
http://hostname/portfolio/123?portfolioIdRequest=456
那么参数“portfolioIdRequest”的值为“456”。
@PathVariable 类似地将 URI 模板变量“portfolioIdPath”的值绑定(bind)到方法参数“portfolioIdPath”。例如,如果您的 URI 是
/portfolio/123
那么“portfolioIdPath”方法参数的值为“123”。
关于java - 在 Spring 3.0 GET 请求中,@PathVariable 和 @RequestParam 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4073970/