Spring mvc 我可以在SpringMVC的RequestMapping中为路径变量设置默认值吗?
是否可以在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){ 在这种情况下,如果我访问的页面没有页码,我想将默认值设置为1Spring 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
这可能吗?无法设置默认值,但可以创建两种方法:
@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
方法你想要的价值。