SpringMVC允许入参为空的方法:required = false

场景:根据订单id查询订单 或者 根据开始日期和结束日期查询订单。非此即彼的条件关系。

        需要允许另一条件的参数为空。否则没传另一条件的参数会报错。


@GetMapping("/unload/histogram")

public PortUnloadHistogramMessage getPortUnloadHistogramMessage(
@RequestParam(name = "orderId", required = false) Integer orderId,
@RequestParam(name = "startDate", required = false) String startDate,
@RequestParam(name = "endDate", required = false) String endDate) {
return analysisPageService.getPortUnloadHistogramMessage(orderId, startDate, endDate);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章