是否有可能在SpringMVC中为@PathVariable设置默认值?
@RequestMapping(value = {"/core/organization/{pageNumber}", "/core/organization"} , method = RequestMethod.GET)
public String list(@PathVariable Integer pageNumber, ModelMap modelMap) {
在这种情况下.如果我访问没有pageNumber的页面,我想将默认值设置为1.
那可能吗?
无法设置默认值,但您可以创建两种方法:
@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;
...
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4760 次 |
| 最近记录: |