【发布时间】:2020-10-18 01:05:29
【问题描述】:
我正在开发 Spring REST API 并拥有以下控制器:
@RestController
@RequestMapping(
value = "/api/Test",
produces = "application/json"
)
public class MyController {
@RequestMapping(method = RequestMethod.POST)
public Response serviceRequest(@Valid @RequestBody ServiceRequest myServiceRequest) {
....
}
}
ServiceRequest 的结构如下:
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class ServiceRequest {
@NotBlank
private LocalDate fromDate;
@NotBlank
private LocalDate toDate;
}
我的任务是引入基于 fromDate 和 toDate 字段值组合的验证:如果它们之间的时间段超过 1 周,那么验证应该会失败。
请问存档的最佳方法是什么?
【问题讨论】:
标签: spring-boot rest validation