我有
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
SessionInfo register(UserProfile profileJson){
...
}
Run Code Online (Sandbox Code Playgroud)
我以这种方式传递profileJson:
http://server/url?profileJson={"email": "mymail@gmail.com"}
Run Code Online (Sandbox Code Playgroud)
但我的profileJson对象具有所有空字段.我该怎么办才能让春天解析我的json?
我已经阅读了许多类似的问题,包括:JQuery,Spring MVC @RequestBody和JSON - 使它 与JQuery/Ajax和Spring 一起使用JSON请求
要求是服务器只接受application/json类型.我正在使用Spring MVC控制器.代码通过@ResponseBody以JSON形式发送响应.我想通过Spring MVC Controller中的@RequestBody获取信息.我正在使用JSP将JSON发送到Spring MVC Controller.我的代码和Spring MVC如下所示:
我是JSON和Javascript的新手.
JSP - index.jsp
<%@page language="java" contentType="text/html"%>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$('#myForm').on('submit', function(e) {
var frm = $("#myForm");
var dat = JSON.stringify(frm.serializeArray());
$.ajax({
type: 'POST',
url: $('#myForm').attr('action'),
data: dat,
contentType: 'application/json',
dataType: 'json',
error: function() {
alert('failure');
}
success: function(hxr) {
alert("Success: " + xhr);
}
});
);
};
</script>
</head>
<body>
<h2>Application</h2>
<form id="myForm" action="/application/save" method="POST" accept="application/json" onclick="i()">
<input type="text" …Run Code Online (Sandbox Code Playgroud) 如何将 Map 参数作为 url 中的 GET 参数传递给 Spring REST 控制器?