我正在尝试将一些数据作为JSON发送到Spring控制器。这是代码:
$(document).ready(function() {
$("#searchbutton").click(function() {
$.ajax({
type: "POST",
url: "/cinestop/searchMovie",
data: JSON.stringify(getQuery()),
contentType: "application/json; charset=UTF-8",
Accept: "application/json",
});
});
});
function getQuery() {
var obj = {}
obj["title"] = $("#home_searchMediaInputText").val();
return obj;
}
这是我的Spring控制器:
@RequestMapping(method = RequestMethod.POST, value = "/searchMovie")
public ModelAndView displayMatchingMovies(@RequestBody final MovieQueryModel movieQuery) {
//correct the spelling first, and then search, to be done
System.out.println(movieQuery.getTitle());
List<MovieInfoModelList> matchingMovieModels = movieInfoDaoImpl.getMovieInfoForListing(movieQuery.getTitle());
return null;
}
我有Jackson设置和所有,但服务器似乎不理解客户端发送的JSON。谁能告诉我我可能做错了什么?
谢谢!