AngularJS-带复选框的Spring POST请求

AngularJS-带复选框的Spring POST请求,angularjs,spring-mvc,spring-boot,Angularjs,Spring Mvc,Spring Boot,我目前正在学习使用Sprint引导和POST请求的AngularJS。我知道后端工作正常,但是,我正在试图找出使用复选框和Spring Boot MVC可能存在的问题。如果我的代码不好,还是新的,请原谅 错误消息: { "status" : "400", "cause" : null, "method" : "POST", "message" : "Required request body is missing: public void com.velatt.dartentitleme

我目前正在学习使用Sprint引导和POST请求的AngularJS。我知道后端工作正常,但是,我正在试图找出使用复选框和Spring Boot MVC可能存在的问题。如果我的代码不好,还是新的,请原谅

错误消息:

{
 "status" : "400",
 "cause" : null,
 "method" : "POST",
 "message" : "Required request body is missing: public void com.velatt.dartentitlements.api.SiteController.addServicesToSite(java.lang.Long,org.springframework.hateoas.Resources<com.velatt.dartentitlements.domain.DeService>) throws java.net.URISyntaxException",
 "exception" : "HttpMessageNotReadableException",
 "path" : "/sites/1/services",
 "error" : "Bad Request"
}
{
“状态”:“400”,
“原因”:空,
“方法”:“发布”,
“消息”:“缺少必需的请求正文:public void com.velatt.dartAuthentications.api.SiteController.addServicesToSite(java.lang.Long,org.springframework.hateoas.Resources)抛出java.net.urisyntaxeption”,
“异常”:“HttpMessageDataableException”,
“路径”:“/站点/1/服务”,
“错误”:“错误请求”
}

您必须按如下方式从ajax中传递正文:

        $http({
            method: 'POST',
            url: "/sites/" + $scope.targetEntity.siteId + "/services",
            headers: {'Content-Type': 'application/x-www-form-urlencoded'},
            data:addRequest,
        }).then(function (response) {
            $scope.services = response.data;
        });

试试这样的

安格拉斯

// create array to hold request data
var selectedObjArray = [];

// push data to array.
 selectedObjArray.push(....);


$http({
        method: 'POST',
        url: "/sites/" + $scope.targetEntity.siteId + "/services",
        headers: {'Content-Type': 'application/json'},   // change content type to json
        data:selectedObjArray ,
    }).then(function (response) {
        $scope.services = response.data;
    });
春季MVC

@RequestMapping(value = "/sites/{id}/services", method = RequestMethod.POST, headers = { "Content-type=application/json" })
public void addServicesToSite(@PathVariable Long id, @RequestBody List<DeService> incoming) throws URISyntaxException {
    for (Link link : incoming.getLinks()) {
        DeService deService = utilityService.getDomainObjectFromUriString(link.getHref(), DeService.class);
        service.addServiceToSite(id, deService);
    }
}
@RequestMapping(value=“/sites/{id}/services”,method=RequestMethod.POST,headers={“Content type=application/json”})
public void addServicesToSite(@PathVariable Long id,@RequestBody List incoming)引发URISyntaxException{
for(链接:incoming.getLinks()){
DeService DeService=utilityService.GetDomainObjectFromUristing(link.getHref(),DeService.class);
service.addServiceToSite(id,deService);
}
}