作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下电话
$.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/
我是一名优秀的程序员,十分优秀!