我有一个任务列表存储在我的数据库中。我想按日期(完成日期)筛选任务,如何通过$http get请求传递日期。我尝试了一些代码,但是它报错了。能否有人帮助我。
Angular:
Angular:
$scope.date=1468175400000;
var deadline = new Date($scope.date);
$http.get(
'/user/task/gettasks/?status=' + $scope.status
+ '&priority=' + $scope.priority
+ '&projectId=' + $scope.project+'&deadline='+deadline).success(
function(response) {
debugger
$scope.tasks = response;
}).error(function(error) {
console.log(error)
})
服务(Spring):
@RequestMapping("/gettasks")
@JsonView({ TaskJsonView.Summary.class })
public List<Task> getTasks(@RequestParam(value="status" ) String status,
@RequestParam("priority") String priority,
@RequestParam("projectId") String projectId,@RequestParam("deadline") Long deadline) {
System.out.println(deadline);
return taskControllerService.getTasks(status, priority, projectId,deadline);
}
错误:
Object {
timestamp: 1468819101831,
status: 400,
error: "Bad Request",
exception: "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",
message: "Failed to convert value of type [java.lang.String]… "
MonJul11201600: 00: 00 GMT0530(IndiaStandardTime)
""…
}
error: "Bad Request"
exception: "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException"
message: "Failed to convert value of type [java.lang.String] to required type [java.lang.Long]; nested exception is java.lang.NumberFormatException: For input string: "
MonJul11201600: 00: 00 GMT0530(IndiaStandardTime)
""
path: "/user/task/gettasks/"
status: 400 timestamp: 1468819101831 proto: Object
deadline
。改为传递deadline.getTime()
,这将以长时间戳的形式发送截止日期。 - Cyril Cherian