org.springframework.http.converter.HttpMessageNotReadableException:缺少必需的请求正文:

org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing:

我有一个 'startDate 和 'endDate' 的列表,它通过 $http Post 请求传递给控制器​​,但它抛出了 subject.My 代码中提到的错误如下

$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 class 如下所示

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;
    }

}

我无法通过它抛出的错误来定位问题出在哪里,它没有到达控制器。

尝试将 auditCycleList 作为 RequestBody 参数发送,正如控制器所期望的那样:

您可以像这样构建请求:

var req = {
   method: 'POST',
   url: 'PlanAuditController/saveUpdateAnualAudit',
   headers: {
     'Content-Type': "application/json"
   },
   data: $scope.auditCycleLst
}

$http(req).success(function(){...}).error(function(){...});