如何从 POJO 自定义和覆盖参数值?
How to customized and Override Parameter Values from POJO?
我正在研究 Spring Boot v2.2.6.RELEASE 和 Open API 集成示例。此示例能够使用 20 个不同的参数进行搜索。所以这个 POJO class 持有 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 class
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;
.........
..............
.............
}
您可以直接将带有注释 @ParameterObject
的对象 CustomSearchDto 传递给它。
这是文档的 link:
我正在研究 Spring Boot v2.2.6.RELEASE 和 Open API 集成示例。此示例能够使用 20 个不同的参数进行搜索。所以这个 POJO class 持有 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 class
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;
.........
..............
.............
}
您可以直接将带有注释 @ParameterObject
的对象 CustomSearchDto 传递给它。
这是文档的 link: