我正在发送一个带有 json 的 POST 请求,如下所示:
$.ajax({
type: "POST",
url: "myurl.htm",
contentType: "application/json",
data: '{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}',
dataType: "json"
});
Network
当我通过传递以下有效负载查看此请求时
{"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
但是,我希望请求负载为:
mydata: {"val1":"something","stuff":[{"val1":"value1","data":"Someone"}]}
因为我的控制器接受以下内容:
@RequestMapping(headers ={"Accept=application/json"},value="/myurl.htm", method= RequestMethod.POST)
public ModelAndView mymethod(
@RequestParam(value="mydata", required=false) String mydata {
logger.info(mydata);
}
所以我需要一种方法来简单地为我作为 POST 请求发送到服务器的 json 数据提供一个参数名称。