我正在发送一个对象列表来请求正文,如下所示:
@PatchMapping("/branches")
public MicApiResponse<Void> updateForManyBranches(
@RequestBody List<@Valid RepresentativeForManyBranchesRequest> req) throws MicClientException {
service.updateForManyBranches(req);
return MicApiResponse.succeed();
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class RepresentativeForManyBranchesRequest {
@Valid
private RepresentativeUserForManyBranchesRequest representativeUsers;
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class RepresentativeUserForManyBranchesRequest {
private String id;
@Required
private String userId;
@Required
@Length(min = 1, max = 100)
private String name;
@Required
@Length(min = 1, max = 100)
private String position;}
当我仅发送一个对象到请求正文时,这些注释 @Required 和 @Length 起作用,但是当我发送对象列表时,它们不起作用。我应该怎么做才能解决这个问题?非常感谢
我觉得你应该这样写
public MicApiResponse<Void> updateForManyBranches(@RequestBody @Valid List<RepresentativeForManyBranchesRequest> req)