我正在尝试向服务器发送ajax POST请求并检索响应。
我的问题是,当我提交表单时,我的@RequestBody参数是空的。
我按照这个教程做了同样的事情。 http://www.mkyong.com/spring-mvc/spring-4-mvc-ajax-hello-world-example/
代码的相关部分:
控制器:
@JsonView(Views.Public.class)
@RequestMapping(value = "searchEvents", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ModelAndView findEvents(HttpServletRequest request, HttpServletResponse response, @RequestBody EventFilterBean eventFilterBean) {
///
}
的index.jsp
var search = {}
search["eventName"] = $("#eventName").val();
$.ajax({
type : "POST",
contentType : "application/json",
url : "searchEvents",
data : JSON.stringify(search),
dataType : 'json',
timeout : 100000
});
在pom.xml中我添加了
com.fasterxml.jackson.core
jackson-core
2.9.0.pr3
com.fasterxml.jackson.core
jackson-databind
2.9.0.pr3
我试图在谷歌上找到解决方案,但我无法做到。提前谢谢你的帮助。