【问题标题】:How to customized and Override Parameter Values from POJO?如何自定义和覆盖 POJO 中的参数值?
【发布时间】:2023-04-07 04:21:02
【问题描述】:

我正在研究 Spring Boot v2.2.6.RELEASE 和 Open API 集成示例。此示例具有使用 20 个不同参数进行搜索的能力。所以这个 POJO 类拥有CustomSearchDto 这 20 个不同的值。

在 POJO 中,我使用了 orgName,但 @parameter(in = ParameterIn.QUERY, name = "orgizationName", 不知何故我想覆盖变量名。我必须这样做。有什么办法吗?

@Parameter(in = ParameterIn.QUERY, name = "orgizationName", schema = @Schema(type = "string")) 
@Parameter(in = ParameterIn.QUERY, name = "employeeId", schema = @Schema(type = "string")) 
@Parameter(in = ParameterIn.QUERY, name = "emailId", schema = @Schema(type = "string")) 
@Parameter(in=ParameterIn.QUERY, name="page", description="Results page you want to retrieve (0..N)", schema=@Schema(defaultValue = "0"))
    @Parameter(in=ParameterIn.QUERY, name="size", description="Number of records per page.", schema=@Schema(defaultValue = "30"))
@GetMapping(value = "/employees/organizations")
public ResponseEntity<PagedModel<Employees>> search(CustomSearchDto requestparams,
        @Parameter(hidden=true) Pageable pageRequest) {

    ......
    ........

    return new ResponseEntity<>(model, HttpStatus.OK);
}

这是我的自定义 DTO 类

public class CustomSearchDto {
    @Schema(description = "", type = "string", example = " ")
    private String orgName;

    @Schema(description = "", type = "string", example = " ")
    private String empId;

    @Schema(description = "", type = "integer", example = "null")
    private Integer email;

    .........
    ..............
    .............
}

【问题讨论】:

    标签: spring-boot springdoc springdoc-openui


    【解决方案1】:

    您可以使用注释@ParameterObject 直接传递对象CustomSearchDto。

    这是文档的链接:

    【讨论】:

      猜你喜欢
      • 2014-05-10
      • 2020-04-28
      • 2014-02-15
      • 2017-06-05
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      • 1970-01-01
      相关资源
      最近更新 更多