Spring允许对RequestParams执行Optional。如何为查询参数执行此操作?
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Page<Deal> getDeals(Optional<PageRange> pageRange) {
return dealService.findDeals(pageRange.orElse(DEFAULT_PAGE_RANGE));
}
查询参数包装器:
@Value
@Builder
@AllArgsConstructor
public class PageRange {
int page;
int size;
}
如果未传递任何页面或大小,则会失败。为什么呢?