Controller中RequestParam接收日期参数

忘是亡心i 2022-10-28 15:24 297阅读 0赞

一些报表的查询中经常有按时间日期查询,前端传参可以用json后端可以用对象来接收, 前端用formdata提交,后台就用@RequestParam来接收,不过这里接收的是字符串,在使用的时候需要转换一下

  1. @PostMapping("/export")
  2. public void export(
  3. @RequestParam(value = "pageNo", required = false) String pageNo,
  4. @RequestParam(value = "size", required = false) String size,
  5. @RequestParam(value = "peopleName", required = false) String peopleName,
  6. @RequestParam(value = "phone", required = false) String phone,
  7. @RequestParam(value = "checkPlaceId", required = false) String checkPlaceId,
  8. @RequestParam(value = "checkStartTime", required = false) String checkStartTime,
  9. @RequestParam(value = "checkEndTime", required = false) String checkEndTime,
  10. HttpServletResponse response
  11. ) {
  12. HealthReservation healthReservation = new HealthReservation();
  13. healthReservation.setPageNo(StrUtil.isNotBlank(pageNo) ? Integer.valueOf(pageNo) : null);
  14. healthReservation.setSize(StrUtil.isNotBlank(size) ? Integer.valueOf(size) : null);
  15. healthReservation.setPeopleName(StrUtil.isNotBlank(peopleName) ? peopleName : null);
  16. healthReservation.setPhone(StrUtil.isNotBlank(phone) ? phone : null);
  17. healthReservation.setCheckStartTime(StrUtil.isNotBlank(checkStartTime) ? DateUtil.parse(checkStartTime) : null);
  18. healthReservation.setCheckEndTime(StrUtil.isNotBlank(checkEndTime) ? DateUtil.parse(checkEndTime) : null);
  19. healthReservationService.export(healthReservation, response);
  20. }

发表评论

表情:
评论列表 (有 0 条评论,297人围观)

还没有评论,来说两句吧...

相关阅读