首页 > 解决方案 > 对象='customerService' 的验证失败。错误数:2

问题描述

我无法找到错误页面上显示的两个验证错误:

message: "Validation failed for object='customerService'. Error count: 2"
error: "Bad Request"
errors: [{,…}, {,…}]
0: {,…}
arguments: [{codes: ["customerService.result", "result"], arguments: null, defaultMessage: "result",…}]
bindingFailure: false
code: "NotNull"
codes: ["NotNull.customerService.result", "NotNull.result", "NotNull.com.paguefacil.domain.admin.Result",…]
defaultMessage: "must not be null"
field: "result"
objectName: "customerService"
rejectedValue: null
1: {,…}
arguments: [,…]
bindingFailure: false
code: "NotEmpty"
codes: ["NotEmpty.customerService.description", "NotEmpty.description", "NotEmpty.java.lang.String",…]
defaultMessage: "must not be empty"
field: "description"
objectName: "customerService"
rejectedValue: null

客户服务.java

public interface Validation {
    interface Update {}
}

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
@JsonView(Json.Base.class)
private Long id;

@NotEmpty(groups = { Default.class, CustomerService.Validation.Update.class })
@Size(max = 2000, groups = { Default.class, CustomerService.Validation.Update.class })
@JsonView(Json.Base.class)
private String description;

@NotNull
@Enumerated(EnumType.STRING)
@JsonView(Json.Base.class)
private Status status = Status.DRAFT;

@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnoreProperties("charges")
@JsonView(Json.WithOrder.class)
private Order order;

@NotNull(groups = {CustomerService.Validation.Update.class })
@ManyToOne(fetch = FetchType.LAZY)
@JsonView(Json.WithResult.class)
private Result result;

@ManyToOne(fetch = FetchType.LAZY)
@JsonView(Json.WithUser.class)
private User user;

@JsonView(Json.Base.class)
private Instant serviceDate;

@Enumerated(EnumType.STRING)
@JsonView(Json.Base.class)
private ErrorCode errorCode;

@JsonView(Json.Base.class)
private String exception;

接口:

@PostMapping("/customers-services/{id}/finish")
@Timed
public ResponseEntity<?> finish(@PathVariable final Long id, 
@Validated(CustomerService.Validation.Update.class) @RequestBodyfinal CustomerService customerService) {

    log.debug(o -> o.with("REST request to add follow up to CustomerService : {}", id));

    return ResponseBuilder.ok()
            .from(() -> customerServiceRepository.findOneActiveById(id)
                    .orElseThrow(() -> NotFoundError.with("Couldn't find CustomerService by requested Id.")))
            .and(dbCustomerService -> userRepository.getCurrentUser()
                    .flatMap(user -> customerServiceService.finish(dbCustomerService, customerService, user))
                    .orElseThrow(() -> ServerError.with("Couldn't finish CustomerService.")))
            .withoutBody()
            .build();
}

标签: javaspringspring-bootspring-mvcspring-data

解决方案


推荐阅读