【发布时间】:2014-02-13 06:17:23
【问题描述】:
我正在使用 Spring data jpa 和 Spring MVC 并进行 ajax 调用以更新 jsp 页面,但在 google chorme 中出现错误:
POST http://localhost:8080/pagesjaunes/loadfonction 500 (Erreur Interne de Servlet) jquery-1.10.2.js:8706
send jquery-1.10.2.js:8706
x.extend.ajax jquery-1.10.2.js:8136
(anonymous function) ajoutcontact.js:15
x.event.dispatch jquery-1.10.2.js:5095
v.handle jquery-1.10.2.js:4766
我的 ajax 调用如下所示:
$.ajax({
url : 'loadfonction',
type : 'post',
data : { "idquality" : idquality },
success : function(fonctions) {
[...]
},
error : function(){
alert("error");
}
});
我的控制器
@RequestMapping(value="/loadfonction")
public @ResponseBody
Set<Fonction> loadfonction(Map<String, Object> model, HttpServletRequest request) {
return qualiteRepo.findOne(Integer.valueOf(request.getParameter("idquality"))).getFonctions();
}
Fonction 是我映射的实体:
@Entity
@Table(name = "fonction", catalog = "pagesjaunes")
public class Fonction implements java.io.Serializable {
[...]
}
Set<Fonction> 的作用是什么?因为我测试了其他代码并且它的工作:
@RequestMapping(value="/loadfonction")
public @ResponseBody
Set<Fonction> loadfonction(Map<String, Object> model, HttpServletRequest request) {
Set<String> test = new HashSet<String>(0);
test.add("yous");
test.add("cc");
test.add("fz");
return test;
}
我的实体Fonction
@Entity
@Table(name = "fonction", catalog = "pagesjaunes")
public class Fonction implements java.io.Serializable {
private Integer id;
private Qualite qualite;
private String nom;
private Set<Contact> contacts = new HashSet<Contact>(0);
private Set<Domaine> domaines = new HashSet<Domaine>(0);
public Fonction() {
}
public Fonction(String nom) {
this.nom = nom;
}
public Fonction(String nom, Qualite qualite) {
this.qualite = qualite;
this.nom = nom;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_qualite")
public Qualite getQualite() {
return this.qualite;
}
public void setQualite(Qualite qualite) {
this.qualite = qualite;
}
@Column(name = "nom", nullable = false, length = 20)
public String getNom() {
return this.nom;
}
public void setNom(String nom) {
this.nom = nom;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "fonction")
public Set<Contact> getContacts() {
return this.contacts;
}
public void setContacts(Set<Contact> contacts) {
this.contacts = contacts;
}
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(name = "fonction_domaine", catalog = "pagesjaunes", joinColumns = { @JoinColumn(name = "id_fonction", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "id_domaine", nullable = false, updatable = false) })
public Set<Domaine> getDomaines() {
return this.domaines;
}
public void setDomaines(Set<Domaine> domaines) {
this.domaines = domaines;
}
}
【问题讨论】:
-
能否提供服务器端堆栈跟踪(如果有)?
-
服务器端什么都没发生!
-
request.getParameter("idquality")是否返回预期值?如果是,qualiteRepo.findOne(Integer.valueOf(request.getParameter("idquality")))也会返回预期的Qualite(我猜)? -
是的,数据正在从数据库中检索,我尝试
qualiteRepo.findOne(Integer.valueOf(request.getParameter("idquality"))).getFonctions().size(),他返回了正确的大小。 -
尝试在
Fonction类的以下方法上添加org.codehaus.jackson.annotate包中的@JsonIgnore注解,看看是否仍然出现错误:getQualite()、getContacts()和@987654341 @.
标签: jquery ajax spring-mvc spring-data