在spring mvc中,注解@PathVariable可以获得路径参数,但如果我想让路径参数可选呢?
@GetMapping({"/get/{offset}/{count}","/get/{offset}","/get/{offset}","/get"})
public void getGoods(@PathVariable(required = false) Integer offset,@PathVariable(required = false) Integer count){
System.out.println("offset:"+offset+"\ncount:"+count+"\n");
}
此时在这个例子中,offset和count都是可选的了,但是count存在时offset必须存在。
本文介绍如何在SpringMVC中使用@PathVariable注解来实现路径参数的可选项功能,通过设置required属性为false使参数变为可选,并且演示了一个具体的示例代码。
1055

被折叠的 条评论
为什么被折叠?



