0

我迁移到 springfox 3.0.0 并在迁移后招摇开始根据需要显示一些查询参数

昂首阔步

我想拥有相同的方法签名,但通过参数识别请求的差异例如:

@ApiAliasFor(ApiUser.class)
@GetMapping(path = "/{id}")
@PreAuthorize("@userAuthority.isTrueUser(#id) || @userAuthority.hasPermissionFor(#id, 'V_U')")
public UserDto get(@PathVariable @NotNull Long id) {
    log.info("Request: get user by id. User with pseudonyms. Details: user.id={}", id);
    User user = userService.findByIdIncludingPseudonyms(id).orElseThrow(() -> new EntityNotFoundException(ErrorDetail.USER_NOT_FOUND));
    return conversionService.convert(user, UserDto.class);
}

@ApiOperation(value = "Find user by id")
@ApiImplicitParam(name = "include[association]", dataType = "boolean", paramType = "query",
        value = "Get user with association included in response. Example ?include[association]=true")
@ApiResponses(value = {
        @ApiResponse(code = 404, message = "User with this id doesn't exist", response = ErrorDetail.class)
})
@GetMapping(value = "/{id}", params = {"include[association]=true"})
@PreAuthorize("@userAuthority.isTrueUser(#id) || @userAuthority.hasPermissionFor(#id, 'V_U')")
public AssociatedUserDto getAssociatedById(@PathVariable @NotNull Long id) {
    log.info("Request: get user by id. User with associations. Details: user.id={}", id);
    AssociatedUser associatedUser = userService.findAssociatedById(id).orElseThrow(() -> new EntityNotFoundException(ErrorDetail.USER_NOT_FOUND));
    return conversionService.convert(associatedUser, AssociatedUserDto.class);
}

结果,我根据需要具有include[association]参数,但我想将其作为可选参数。

4

0 回答 0