AngularJS + Spring MVC 400错误请求错误

时间:2016-10-17 11:36:50

标签: angularjs spring spring-mvc

我正在使用$ http服务向SPRING @RestController发送帖子请求,但我收到400 bad request响应我无法弄清楚我错过了什么,我已经尝试过了与另一个对象,它工作正常。

java对象

public class CmdOperationProxy {

    private String name;

    private String date;

    private double soldPrice;

    private int quantity;

    // getters and setters

}

我的控制器

@RequestMapping(value="/rest/add/operation", method = RequestMethod.POST)
public  ResponseEntity<Void> addOperationToCmd(@RequestBody CmdOperationProxy op
                                ,HttpServletRequest request,UriComponentsBuilder ucBuilder) throws IOException{ 
    System.out.println("--------------------------------------");
    System.out.println(op.getDate());
    System.out.println(op.getName());
    System.out.println(op.getQuantity());
    System.out.println(op.getSoldPrice());

    HttpHeaders headers = new HttpHeaders();
     headers.add("Accept", "application/json");
    headers.setLocation(ucBuilder.path("/rest/articles").buildAndExpand(cmdproxy.getDate()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

角度服务

function addOperation(){
     var deferred = $q.defer();
    op = { 'name' : 'hello world', 'soldPrice' : 40.25 , 'quantity' : 1 , 'date' : '15-10-2016' } 
    $http.post(URI+"/add/operation",op)
         .then(
            function (response) {
                deferred.resolve(response.data);
            },
            function(errResponse){
                console.error('Error while adding operation to cmd');
                deferred.reject(errResponse);
            }
       );
    return deferred.promise;  
 } 

0 个答案:

没有答案