我正在使用Spring Boot + Spring Data Mongo + Spring REST + Spring HATEOAS来实现 REST 端点。
由于我们传递了超过 5 个查询参数(组织的专有设置,应该不传递),所以我想创建一个 EmployeeDto 类并将该类传递给控制器
@GetMapping(value = "/employees", produces = {MediaType.APPLICATION_JSON })
public ResponseEntity<PagedModel<EmployeeModel>> findEmployees(
EmployeeDto dto,
@Parameter(hidden=true) String sort,
@Parameter(hidden=true) String order,
@Parameter(hidden=true) Pageable pageRequest) {
// Add needed logic
......
......
......
PagedModel<EmployeeModel> model = employeePagedAssembler.toModel(response, employeeAssembler);
return new ResponseEntity<>(model, HttpStatus.OK);
}
它显示的 Swagger UI 像 -
{
"firstName": "string",
"lastName": "string",
"age": 0,
"languageCd": "string",
"isActive": "string",
"email": "string",
"regionCd": "string"
}
卷曲命令:
curl -X GET " http://localhost:8080/employee-data/employees/geographies?firstName=string&lastName=string&age=0&languageCd=string&isActive=string&email=string®ionCd=string&page=0&size=25&sort=firstName&order=ASC " -H " 接受:应用程序/json"
EmployeeDto.java
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
@Schema
public class EmployeeDto {
@Schema(description = AppConstants.FIRSTNAME, defaultValue="")
private String firstName;
@Schema(description = AppConstants.LASTNAME, defaultValue="")
private String lastName;
@Schema(description = AppConstants.AGE, defaultValue="")
private Integer age;
@Schema(description = AppConstants.LANG_CD_DESC, defaultValue="0")
private String languageCd;
@Schema(description = AppConstants.ISACTIVE, defaultValue="")
private String isActive;
@Schema(description = AppConstants.EMAIL, defaultValue="")
private String email;
@Schema(description = AppConstants.REGION_CD_DESC, defaultValue="")
private String regionCd;
}
我在寻找 -
1)如何为每个字段设置默认值,而不是看起来默认的“字符串”?
2) 如何简单地允许在 OAS3 UI 中查看实际查询参数?货币,它看起来像身体。