java springmvc@PathVariable個別パラメータは空の処理方法である可能性があります

1986 ワード

問: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 getOrderList(@PathVariable String pin, @PathVariable(required = false) String phone) {
  }