gpt4 book ai didi

java - 如何在 Java swagger UI 中将对象数组作为参数传递?

转载 作者:太空宇宙 更新时间:2023-11-04 11:51:37 24 4
gpt4 key购买 nike

我需要在 java Swagger UI 中传递一个对象数组作为参数。我做不到。但是我可以轻松地将字符串数组作为参数传递。但无法弄清楚如何传递嵌套在另一个类或 DTO 中的对象数组。我正在使用 Java Spring 并开发 RESTful Web 服务。

下面是我的第一个 DTO,它在我的 REST api 中作为 ModelAttribute 作为参数传递:

public class BusinessDetailsDTO {

private BusinessMembersDTO[] businessMembers;

public BusinessMembersDTO[] getBusinessMembers() {
return businessMembers;
}
public void setBusinessMembers(BusinessMembersDTO[] businessMembers) {
this.businessMembers = businessMembers;
}
}

下面是第二个 DTO,其数组在第一个 DTO 中成为属性:

public class BusinessMembersDTO {

private String ownerRole;
private String businessLocation;
private Long memberId;
//getter setter below
}

下面是 Controller 方法定义:

@ApiOperation(value = "Add business info")
@RequestMapping(method = RequestMethod.POST, value = "/addBusinessInfo", produces={"application/json"})
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Success", response = ResponseEntity.class),
@ApiResponse(code = 401, message = "Unauthorized"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Not Found"),
@ApiResponse(code = 500, message = "Failure") })
public ResponseEntity<BusinessDetails> addBusinessInfo(@RequestParam(
@ModelAttribute BusinessDetailsDTO businessDetailsDTO) {

我的问题是,我无法弄清楚应该如何传递 BusinessMembersDTO 中存在的值ownerRoleswagger UI 在 businessMembers 成员字段旁边的 DataType 列中显示 Array[]

请帮忙。

最佳答案

尝试将 BusinessDetailsDTO 直接作为 ApiResponse 中的响应,如下所示

@ApiResponse(code = 200, message = "Success", response = BusinessDetailsDTO.class)

关于java - 如何在 Java swagger UI 中将对象数组作为参数传递?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41776845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com