我有一个'startDate和'endDate'列表,它通过$ http Post请求传递给控制器,但它正在抛出主题中提到的错误。我的代码如下
$scope.saveUpdateAnualAudit=function(auditPlanLst)
{
$scope.auditCycleLst = [];
$scope.auditCycleLst = JSON.stringify(auditPlanLst);
//auditPlanLst is a list of startDate and endDate captured from the view
console.log("$scope.auditCycleLst "+$scope.auditCycleLst);
$http({
method: 'POST',
url: "PlanAuditController/saveUpdateAnualAudit/"+$scope.auditCycleLst,
}).success(function(data, status) {
})
.error(function(data, status) {
$scope.errorMsg= "<strong>Error!</strong> Failed to retrieve AuditPlan of .";
$scope.showErrorAlert = true;
$scope.showSuccessAlert = false;
});
}
}]);
控制器代码如下
@RequestMapping(value = "/saveUpdateAnualAudit/{auditCycleLst}", method = RequestMethod.POST)
public String saveUpdateAnualAudit(@RequestBody List<AuditCycleJsonVo> auditCycleLst) {
try {
System.out.println("Saved to db");
}catch(Exception e){
e.printStackTrace();
}
return "planAudits";
}
其中AuditCycleJsonVo类如下
public class AuditCycleJsonVo {
private String startDate;
private String endDate;
public String getStartDate() {
return startDate;
}
public void setStartDate(String startDate) {
this.startDate = startDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
}
我无法通过它抛出的错误找到它出错的地方,它不会出现在控制器上。
答案 0 :(得分:0)
尝试将auditCycleList作为 RequestBody 参数发送,正如控制器所期望的那样:
您可以像这样构建请求:
var req = {
method: 'POST',
url: 'PlanAuditController/saveUpdateAnualAudit',
headers: {
'Content-Type': "application/json"
},
data: $scope.auditCycleLst
}
$http(req).success(function(){...}).error(function(){...});