【发布时间】:2021-12-13 17:53:23
【问题描述】:
从 Spring Boot 控制器,我想知道要遵循什么模式来验证 2 个可选日期参数一旦提供就不能为空。换句话说,它们可以为 null 或两者都已填充
public ResponseEntity<CardResponse> getCards(
@RequestParam(required = false) String orderReference,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime orderPlacementDateStart,
@RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime orderPlacementDateEnd,
@PageableDefault(page = DEFAULT_PAGE_NUMBER, size = DEFAULT_PAGE_SIZE) Pageable pageRequest) {
}
我看到了一些类级别的约束,但我不确定是否可以将其应用于 2 个不同的参数?
请告诉我在这种情况下推荐什么?
谢谢
【问题讨论】: