是否可以在 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;
...
}
关于spring-mvc - 我可以在 Spring MVC 的 RequestMapping 中为路径变量设置默认值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28266484/