Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java spring mvc-带post的空json_Java_Jquery_Ajax_Spring Mvc - Fatal编程技术网

Java spring mvc-带post的空json

Java spring mvc-带post的空json,java,jquery,ajax,spring-mvc,Java,Jquery,Ajax,Spring Mvc,我对SpringMVC有一个小问题。基本上,我要做的是使用AJAX将JSON对象发送到服务器 简而言之,JS代码如下: var newUser = { "userId":-1, "userName":name }; var notifRecip = { "emailNotification":jQuery( this ).find( "td:nth-child(3) input[type='checkbox']" ).is( ":checked" ), "smsNotification"

我对SpringMVC有一个小问题。基本上,我要做的是使用AJAX将JSON对象发送到服务器

简而言之,JS代码如下:

var newUser = { "userId":-1, "userName":name };
var notifRecip = {
  "emailNotification":jQuery( this ).find( "td:nth-child(3) input[type='checkbox']" ).is( ":checked" ),
  "smsNotification":jQuery( this ).find( "td:nth-child(4) input[type='checkbox']" ).is( ":checked" ),
  "webNotification":jQuery( this ).find( "td:nth-child(5) input[type='checkbox']" ).is( ":checked" ),
  "user":newUser
};
如果我是对的,它会给我一个有效的JSON对象,其中包含来自表单的数据。是吗?现在我在做ajax帖子:

jQuery.ajax( "/notifications/saveNewUsers/" + notId, {
       dataType:'json',
      contentType:"application/json",
     type:"POST",
    data:( notifRecip )
} )
.success( function ( response )
{
    console.log( response )
} );
到目前为止一切正常,我的控制器接收到带有正确
notId
值的请求:

@RequestMapping(value = "saveNewUsers/{notificationId}", method = RequestMethod.POST, headers = {"content-type=application/json"})
public
@ResponseBody
boolean saveNewUsers( @RequestBody NotificationRecipient notificationRecipient, @PathVariable Integer notificationId )
{
    System.out.println( notificationId + " " + notificationRecipient );
    return false;
}
但控制台输出如下所示:

18:45:10,947 INFO  [stdout] (ajp--127.0.0.1-8009-1) 0 null
我不知道为什么。我是spring mvc的新手,因此任何帮助都将不胜感激。我确实有
Jackson
依赖关系

NotificationRecipient
对象:

public class NotificationRecipient
{
private User user; 
private boolean emailNotification;
private boolean smsNotification;
private boolean webNotification;

//with getters and setters
}
用户

public class User
{
private Integer userId;
private String userName;

//with getters and setters
}

在谷歌搜索了一段时间后:


您需要调用
data:JSON.stringify(notifRecip)
。当我在没有它的情况下发布时,JSON对象中的参数被解析为GET参数(…webnotification=false&smsNotification=false…)

您可以发布JSON,然后发送给控制器吗?(请参阅firebug中的并发布)