将json数据发送到spring mvc控制器时出现错误请求错误

时间:2015-03-09 12:27:40

标签: angularjs spring-mvc

我正在尝试将一些json数据从angular ng网格发送到spring mvc控制器,但是我收到错误 400(错误请求)客户端发送的请求在语法上不正确。。< / p>

这是我的请求Paylod:

[{"orderId":1,"orderTitle":"Xcel","orderDetail":"cash","orderType":"Xcel","orderPriority":"22.0","retailerId":0,"orderRefno":"9.900499743E9","customerName":"high","customerContactno":"pen drive","customerEmailId":"nutral","paymentType":"iffu@gmail.com","orderStatus":"pen drive","reciptDate":null,"bayNumber":"Xcel","deliveredDate":null,"deliveredBy":"Irfan","updatedOn":null,"pudoOutlet":null,"retailer":null,"outletId":0}]

这是我的spring mvc控制器:

@RequestMapping(value="/createorder",method=RequestMethod.POST,headers="Content-Type=application/json")
public @ResponseBody ModelAndView createOrder(@RequestBody Order order){

    System.out.println("hiiiii"+order);
try{


    orderDao.createOrder(order);
    return new ModelAndView("product1.html");
}
catch(Exception e)
{
    System.out.println(e);

}
return new ModelAndView("pr.html");

}

这是我发布的角度控制器:

$scope.save = function() {

    console.log("hii inside save function");
    console.log($scope.mySelections);
    console.log("after myselection")
    var d=$scope.mySelections; 
    console.log("hhhhh" +d);
     $http({

         method: 'POST',

          url: './createorder',
          headers: {'Content-Type': 'application/json'},
          data:d

        }).success(function (data) 
          {
            $scope.status=data;
          });
      };

我很困惑为什么我收到这个错误?是因为我正在向spring mvc控制器发送一些空值吗?如果是,如何解决这个问题?

1 个答案:

答案 0 :(得分:-2)

秩序是一个内在的阶级吗?如果是这样,请尝试将该类放入其自己的文件中。为我工作。