Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 在使用@RequestPram时,参数中包含参数是否冗余?_Spring_Spring Mvc_Request - Fatal编程技术网

Spring 在使用@RequestPram时,参数中包含参数是否冗余?

Spring 在使用@RequestPram时,参数中包含参数是否冗余?,spring,spring-mvc,request,Spring,Spring Mvc,Request,例如: @GetMapping(value = "/artists", params = "genre") public List<Artist> getArtists(@RequestParam String genre) { } @GetMapping(value=“/artists”,params=“genre”) 公共列表getArtists(@RequestParam字符串类型){ } 在params中包含genre是多余的,因为在方法签名中也使用@RequestPar

例如:

@GetMapping(value = "/artists", params = "genre")
public List<Artist> getArtists(@RequestParam String genre) {
}
@GetMapping(value=“/artists”,params=“genre”)
公共列表getArtists(@RequestParam字符串类型){
}
params
中包含
genre
是多余的,因为在方法签名中也使用
@RequestParam
声明它

当尝试为同一URL映射到不同的方法时,方法签名是必须的,还是在注释(和其他HTTP方法特定的变体)中定义参数,元素用于根据查询参数条件缩小请求映射的范围。从:

映射请求的参数,缩小了主映射范围

任何环境的格式都相同:一系列
myParam=myValue
样式的表达式,只有在发现每个此类参数都具有给定值时,才会映射请求。表达式可以通过使用
来求反=运算符,如
myParam=myValue
<还支持code>myParam
样式表达式,请求中必须存在此类参数(允许有任何值)。最后,
!myParam
样式表达式表示指定的参数不应出现在请求中

另一方面,注释允许您将查询参数绑定到方法参数


有关详细信息,请参阅。

为什么不尝试一下,看看会发生什么。只需删除流派参数,看看控件是否仍然使用此方法。我尝试过,它无法区分仅在@RequestParams上查看。也许应该。