java - 对象='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();
}
解决方案
推荐阅读
- python - FileNotFoundError:[Errno 2] 没有这样的文件或目录:'Colorado River Data.csv'
- python - 如何在 Amazon Linux 2 m6g 实例中安装 pyarrow
- javascript - 如何通过忽略对象中的 isDeleted 标志来更新订单值
- unity3d - Unity 2020.1.1f1 服务中没有多人游戏
- sql - 如何使用一条 SQL 语句使记录组无效?
- sql-server - 将 SQL Server 从 Express 升级到 Developer,但仍然无法在 SSMS 中使用开发人员服务器
- slurm - 在 slurm 中打印每个作业使用的 cpu 数量?
- laravel - 如何在 laravel 的 stdClass 中设置新属性
- python - 如何在 Python concurrent.futures.ProcessPoolExecutor 中的父处理器和子处理器之间获得相同的哈希值?
- c++ - std::tie 用于较少的比较和 char 数组