Spring MVC에 약간의 문제가 있습니다. 기본적으로 내가 뭘 하려는지 AJAX와 서버에 JSON 개체를 보내는 것입니다. 내가 옳다 경우spring mvc - null json with post
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 객체를 제공합니다 한마디로
는이 같은 JS 코드를 본다? 지금은 아약스 게시물을하고 있어요 :
jQuery.ajax("/notifications/saveNewUsers/" + notId, {
dataType:'json',
contentType:"application/json",
type:"POST",
data:(notifRecip)
})
.success(function (response)
{
console.log(response)
});
를 지금까지 너무 좋아, 내 컨트롤러 recives 적절한 notId
값을 요청 :
18:45:10,947 INFO [stdout] (ajp--127.0.0.1-8009-1) 0 null
:
@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;
}
그러나 콘솔 출력은 다음과 같다 왜 그런지 모르겠습니다. 나는 봄 mvc에 아주 새롭다 그래서 어떤 도움든지 평가 될 것이다. 나는 Jackson
의존성을해야합니까.
NotificationRecipient
객체 :
public class NotificationRecipient
{
private User user;
private boolean emailNotification;
private boolean smsNotification;
private boolean webNotification;
//with getters and setters
}
및 User
: 당신은 data: JSON.stringify(notifRecip)
를 호출 할 필요가
:
public class User
{
private Integer userId;
private String userName;
//with getters and setters
}
컨트롤러에 JSN을 게시 할 수 있습니까? (방화 광구 그것을 게시) –