【发布时间】:2012-09-03 19:30:22
【问题描述】:
在我阅读的所有关于 Spring 3 对 Spring MVC 的 RESTful 添加的教程和文章中,我只见过一种用于传递查询数据的方法,即通过 @PathVariable、like so:
@RequestMapping(value="/shops/{name}", method=RequestMethod.GET)
public @ResponseBody Shop getShopInJSON(@PathVariable String name) {
...
}
它会响应 http://www.example.com/myservlet/shops/{name} 之类的东西,它可以评估为 http://www.example.com/myservlet/shops/thebestshoparound。
我的问题是:是否可以设置一个 RESTful 接口来接收基于经典查询字符串的请求,例如http://www.example.com/myservlet/shops?name=thebestshoparound,而不是PathVariables?
这似乎是一个非常简单的问题,但我在网上的任何地方都找不到。
【问题讨论】:
标签: spring-mvc query-string spring-3 path-variables