简体   繁体   English

@RequestBody无法正常工作

[英]@RequestBody doesn't work as expected

I am sending a JSON obj to the server which will populate my domain obj Report. 我正在将JSON obj发送到服务器,该服务器将填充我的域obj报告。

public class CustomReport {String name;
String name;
String email;
Date invocieDate;
Date shipDate;
//...getters and setters
}

everything are populated but invoiceDate. 一切都已填充,但invoiceDate。

public void create(@RequestBody CustomReport report, HttpServletRequest request) {      
      System.out.println(report.getShipDate()); 
      System.out.println(report.getInvocieDate()); // gives me null
      System.out.println(report.getName());
}

I checked the request payload from the browser, i think the request is ok 我从浏览器检查了请求有效负载,我认为请求还可以

{"name":"trace","email":"trace@gmail.com","invoiceDate":"2015-01-01T06:00:00.000Z","shipDate":"2015-01-02T06:00:00.000Z"}

my js code is as following: 我的js代码如下:

    $scope.submit = function() {
    console.log($scope.report.invoiceDate); //got value here
    $http.post('/api/request/submit', $scope.report).success(function(data){
        alert("success");
    }).error(function(data,status,headers,config){});

is there anything wrong with my code? 我的代码有什么问题吗? anything I could do to debug? 我能做些什么来调试?

please help, any help will be appreciated. 请帮助,任何帮助将不胜感激。

Look more carefully 仔细看

in the JSON: 在JSON中:

"invoiceDate":"2015-01-01T06:00:00.000Z" 

in the class 在课堂里

Date invocieDate;

In both a name should be the same) 两者名称应相同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM