在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必须存在。

相关文章:

  • 2021-09-03
  • 2022-01-20
  • 2022-01-19
  • 2021-09-18
  • 2021-09-12
  • 2021-08-26
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-29
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案