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
时间多了,文章来源:https://www.toymoban.com/news/detail-808227.html
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即可。文章来源地址https://www.toymoban.com/news/detail-808227.html
到了这里,关于SpringCloud OpenFegin 传递Date类型的参数时,接收端多出14个小时的问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!