想要在Get請求中,傳遞Date參數,以下:html
@GetMapping("/findByPeriodOrderByTimeDesc") public ResponseEntity<List<Message>> getMessagesPeriodByTimeDesc(@RequestParam @DateTimeFormat Date start, @RequestParam @DateTimeFormat Date end) { }
儘管,我這裏使用了DateTimeFormat的註解,然而,Spring依舊把Date參數看成String類型來處理。以前在文章《spring boot中jackson時間格式和東八區的設置》中,使用以下配置:spring
# JACKSON (JacksonProperties) spring.jackson.date-format=yyyy-MM-dd HH:mm:ss spring.jackson.time-zone=GMT+8
DateTimeFormat有沒有相似到配置類?mvc
spring.mvc.date-format=yyyy-MM-dd HH:mm:ss
@GetMapping("/findByPeriodOrderByTimeDesc") public ResponseEntity<List<Message>> getMessagesPeriodByTimeDesc(@RequestParam Date start, @RequestParam Date end) { }