1. 程式人生 > >java [email protected]

java [email protected]

問:假如id為非必需引數,可以為空,應該怎麼處理

@RequestMapping(value = "/get/{id}/{userId}", method = RequestMethod.GET)
    public Result getMemberShip(@PathVariable("id") int id,@PathVariable("userId") int userId) {

可以指定多個匹配路徑

@RequestMapping(value = {"/get/{userId}""/get/{id}/{userId}"}, method = RequestMethod.GET)

然後設定引數非必須

@PathVariable
(required = falseString id

示例

@ApiOperation("獲取訂單介面")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "pin", paramType = "path", dataType = "String", value = "賬號", required = true),
          @ApiImplicitParam(name = "phone", paramType = "path", dataType = "String", value = "電話號碼", required = false)
  })
  @ApiResponses({@ApiResponse(code = 501, message = "自定義異常xxx"), @ApiResponse(code = 500, message = "500", response = Errors.class)})
  @GetMapping(value = {"/list/{pin}/{phone}", "/list/{pin}"})
  public List<OrderBaseVO> getOrderList(@PathVariable String pin, @PathVariable(required = false) String phone) {
  }