http://xiangai.taobao.com
http://shop148612228.taobao.com

spring mvc 之可选路径参数

在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");
    }
  • 1
  • 2
  • 3
  • 4

此时在这个例子中,offset和count都是可选的了,但是count存在时offset必须存在。

posted @ 2020-09-07 17:49  万事俱备就差个程序员  阅读(630)  评论(0编辑  收藏  举报

http://xiangai.taobao.com
http://shop148612228.taobao.com
如果您觉得对您有帮助.领个红包吧.谢谢.
支付宝红包
微信打赏 支付宝打赏