我正在尝试获取要在 Spring 3 MVC 应用程序上呈现的对象列表,并希望通过 Ajax 执行此操作。
所以在我的春季课上,我有:
@RequestMapping(value = "/viewSearchEnquiriesAjax", method = RequestMethod.GET, headers = "Accept=application/json")
public @ResponseBody List<Enquiry> getEnquiriesBySearchAjax(@RequestParam String name) {
Search search = new Search();
search.setFirstName(name);
return searchEnquiries(search);
}
但是当它运行时我得到一个 500(内部服务器错误)。当我在浏览器中调试时,这会表现出来'GET http://localhost:8080/SpringMVC/viewSearchEnquiriesAjax?name=peter 500 (Internal Server Error)'
我可以成功返回一个没有错误的对象。Spring Json 映射器(Jackson)可以正确转换吗?我错过了一些基本的东西吗?
我的javascript如下:
function doAjaxPost() {
// get the form values
var firstName = $('#firstName').val();
$.getJSON("/SpringMVC/viewSearchEnquiriesAjax", { name: firstName }, function(result) {
alert("Success");
});
}
我的查询对象是一个实体:
@Entity
@Table(name = "enquiries")
public class Enquiry implements java.io.Serializable{
private static final long serialVersionUID = -5093725544297637792L;
protected Long id;
protected Date created = new Date();
...
...
public Enquiry() {
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
...
...