首先,我是 var dataObject = {
dateData: New Date('16-01-01 15:30')
}
console.log(dataObject);
$.ajax({
type: "POST",
url: '@Url.Content("~/Service/DateTest")',
dataType: "json",
data: dataObject,
},
success: function (response) {
}
});
}
的新手并尽力使其发挥作用。所以这是我的问题。
我有一个spring MVC项目,该项目应该接收请求有效负载(JSON请求)并在网页上显示有效负载主体。请参阅我的项目内容和下面的控制器类
public ActionResult DateTest(DateObject data)
{
return Json("ok", JsonRequestBehavior.AllowGet);
}
现在,如果我使用Spring
向@Controller
public class CallbackPayloadController {
public CallbackPayloadController() {
System.out.println("In controller class!!!!");
}
@RequestMapping(value = "/requestreceiver", consumes = "application/json", method = RequestMethod.POST)
public void receivePayload(@RequestBody String payload) {
System.out.println("In the controller method....");
System.out.println("Payload is : " + payload);
}
}
发帖,则会显示http://localhost:8080/PayloadReceiver/requestreceiver/
。我发布的Json内容是
POSTMAN
我的HTTP STATUS 404
如下
{
"key":"123"
}
第二个问题是,如果我成功收到有效负载,如何在新网页上显示有效负载内容?
答案 0 :(得分:-1)
尝试将return
语句添加到您的方法中,如下所示:
@RequestMapping(value = "/requestreceiver",consumes="...",method = RequestMethod.POST)
public String receivePayload(...)
...
return "requestreceiver";