gpt4 book ai didi

javascript - JSON : The request sent by the client was syntactically incorrect

转载 作者:行者123 更新时间:2023-12-03 09:44:51 26 4
gpt4 key购买 nike

我有以下电话

$.getJSON("/svrBooking/json/getEmployeesByManager",{
manager: "Paul Walker",
endDate: endDate, --> "Thu May 28 16:52:25 BST 2015"
startDate: startDate, --> "Thu Apr 30 16:52:25 BST 2015"
ajax: 'true'
}, function (result) {...});

这正在调用以下Java代码

@RequestMapping(value="/getEmployeesByManager" , method = RequestMethod.GET)
public @ResponseBody ReservationsCount
getEmployeesByManager(Model model,@RequestParam String manager,@RequestParam Date startDate, @RequestParam Date endDate) throws ParseException{...}

我收到以下错误

GET 'http://localhost:8080/svrBooking/json/getEmployeesByManager?manager=Paul+Walker&endDate=Thu+May+28+16%3A52%3A25+BST+2015&startDate=Thu+Apr+30+16%3A52%3A25+BST+2015&ajax=true'   400 bad request

回复说

The request sent by the client was syntactically incorrect.

当我将 Date 对象传递给 getJSON 调用时,这种情况才开始发生。如果我将日期更改为字符串,一切正常。有谁知道这是怎么回事吗?

最佳答案

看看this所以问题。
Spring不知道如何解析Date参数。您必须在 @RequestParam 之后添加 @DateTimeFormat 注释来告诉 Spring 需要哪种格式。例如:

@RequestParam @DateTimeFormat("MMddyyyy") Date startDate

在 Javascript API 调用中,您必须以指定的格式传递日期。

您还应该能够使用 ISO 格式(我尚未测试过):

@RequestParam @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date startDate

然后在 Javascript API 调用中,您应该使用 toISOString 格式化日期:

$.getJSON("/svrBooking/json/getEmployeesByManager",{
manager: "Paul Walker",
endDate: endDate.toISOString(), --> "2015-06-26T08:38:26.175Z"
startDate: startDate.toISOString(), --> "2015-06-26T08:38:45.304Z"
ajax: 'true'
}, function (result) {...});

关于javascript - JSON : The request sent by the client was syntactically incorrect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31068004/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com