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?
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;
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With