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 我可以在SpringMVC的RequestMapping中为路径变量设置默认值吗?_Spring Mvc - Fatal编程技术网

Spring mvc 我可以在SpringMVC的RequestMapping中为路径变量设置默认值吗?

Spring mvc 我可以在SpringMVC的RequestMapping中为路径变量设置默认值吗?,spring-mvc,Spring Mvc,是否可以在SpringMVC中将@PathVariable设置为默认值 @RequestMapping(value = {"/core/organization/{pageNumber}", "/core/organization"} , method = RequestMethod.GET) public String list(@PathVariable Integer pageNumber, ModelMap modelMap) { @RequestMapping(值={/core

是否可以在SpringMVC中将@PathVariable设置为默认值

@RequestMapping(value = {"/core/organization/{pageNumber}", "/core/organization"} , method = RequestMethod.GET) public String list(@PathVariable Integer pageNumber, ModelMap modelMap) { @RequestMapping(值={/core/organization/{pageNumber},“/core/organization”},方法=RequestMethod.GET) 公共字符串列表(@PathVariable Integer pageNumber,ModelMap ModelMap){ 在这种情况下,如果我访问的页面没有页码,我想将默认值设置为1


这可能吗?

无法设置默认值,但可以创建两种方法:

@RequestMapping(value={/core/organization/{pageNumber},“/core/organization”},method=RequestMethod.GET)
公共字符串列表(@PathVariable Integer pageNumber,ModelMap ModelMap){
...
}
@RequestMapping(值={/core/organization/,“/core/organization”},方法=RequestMethod.GET)
公共字符串列表(@PathVariable Integer pageNumber,ModelMap ModelMap){
整数pageNumber=默认值;
...

}
我不确定这是否是您想要的,但是如果您想要在swagger中显示默认值,您可以使用
@apimplicitparams
/
@apimplicitparam
来注释函数,并使用
defaultValue
paramType=“path”
已指定。

我对此表示怀疑,因为您不能在Java中为方法参数设置默认值不,您不能为路径变量设置默认值,因为如果没有该变量,URL将不同,因此不匹配。您可以始终为
/core/organization
创建映射,该映射在内部使用默认值调用
list
方法你想要的价值。