Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc Can-Spring MVC';s的REST框架是否接受查询字符串而不是PathVariables?_Spring Mvc_Query String_Spring 3_Path Variables - Fatal编程技术网

Spring mvc Can-Spring MVC';s的REST框架是否接受查询字符串而不是PathVariables?

Spring mvc Can-Spring MVC';s的REST框架是否接受查询字符串而不是PathVariables?,spring-mvc,query-string,spring-3,path-variables,Spring Mvc,Query String,Spring 3,Path Variables,在我读过的所有关于Spring3对SpringMVC的RESTful添加的教程和文章中,我只见过一种通过@PathVariable,传递查询数据的方法: 这将响应类似于http://www.example.com/myservlet/shops/{name},可以计算为http://www.example.com/myservlet/shops/thebestshoparound 我的问题是:是否可以设置一个RESTful接口,它接受基于经典查询字符串的请求,例如http://www.examp

在我读过的所有关于Spring3对SpringMVC的RESTful添加的教程和文章中,我只见过一种通过
@PathVariable
,传递查询数据的方法:

这将响应类似于
http://www.example.com/myservlet/shops/{name}
,可以计算为
http://www.example.com/myservlet/shops/thebestshoparound

我的问题是:是否可以设置一个RESTful接口,它接受基于经典查询字符串的请求,例如
http://www.example.com/myservlet/shops?name=thebestshoparound
,而不是
PathVariables

这似乎是一个非常简单的问题,但我在网上的任何地方都找不到它。

是的,请使用注释,下面是一个示例:

public @ResponseBody Shop getShopInJSON(@PathVariable String name, @RequestParam(value="query", required=false) String query) {
    // do stuff
}
public @ResponseBody Shop getShopInJSON(@PathVariable String name, @RequestParam(value="query", required=false) String query) {
    // do stuff
}