Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a default value for a path variable at RequestMapping in SpringMVC?

Tags:

spring-mvc

Is it possibile to set a default value to a @PathVariable in SpringMVC?

 @RequestMapping(value = {"/core/organization/{pageNumber}", "/core/organization"} , method = RequestMethod.GET)
    public String list(@PathVariable Integer pageNumber, ModelMap modelMap) {

In this case. If I access the page without pageNumber I want to set a default value to 1.

Is that possible?

like image 490
Felipe Ferreira do Amaral Avatar asked Feb 01 '15 18:02

Felipe Ferreira do Amaral


1 Answers

There's no way to to set a default value, but you can create two methods:

@RequestMapping(value = {"/core/organization/{pageNumber}", "/core/organization"} , method = RequestMethod.GET)
    public String list(@PathVariable Integer pageNumber, ModelMap modelMap){
...
}


@RequestMapping(value = {"/core/organization/", "/core/organization"} , method = RequestMethod.GET)
    public String list(@PathVariable Integer pageNumber, ModelMap modelMap){
Integer pageNumber=defaultvalue;
...
}
like image 115
user3359139 Avatar answered Sep 20 '22 17:09

user3359139