SpringCloud OpenFegin 传递Date类型的参数时,接收端多出14个小时的问题

SpringCloud OpenFegin 传递Date类型的参数时,接收端多出14个小时的问题

1. OpenFegin写法

入参:

“startTime”: “2024-01-16 00:00:00”, “endTime”: “2024-01-18 23:59:59”,

@GetMapping("/queryDisposalComplete")

JsonResult<Map<String, List<Dto>>> queryDisposalComplete(@RequestParam(value = "startTime", required = false) Date  startTime,  
 @RequestParam(value = "endTime", required = false) Date endTime);
    @GetMapping("/queryDisposalComplete")
    public JsonResult<Map<String, List<Dto>>>> queryDisposalCompleter(@RequestParam(value = "startTime", required = false)  Date startTime,
                                                                                        @RequestParam(value = "endTime", required = false)  Date endTime) {
        log.info("startTime:{},endTime:{}", JSONObject.toJSONString(startTime),JSONObject.toJSONString(endTime));
        Map<String, List<Dto>> map = service.queryDisposalComplete(startTime,endTime);
        return  JsonResult.ok( map);
    }

对应log

 startTime:1705384800000,endTime:1705557599000

Unix 时间戳 转成 北京时间startTime: 2024-01-16 14:00:00 endTime:2024-01-18 13:59:59

时间多了,

2. 既然用Date 接收导致时间多了,那么改用String 是不是就可以接收到原始数据了
@GetMapping("/queryDisposalComplete")
JsonResult<Map<String, List<Dto>>> queryDisposalComplete(@RequestParam(value = "startTime", required = false) String startTime,  
 @RequestParam(value = "endTime", required = false) String endTime);

然后根据String 类型转成Date即可。