我使用spring mvc。 这是我的旧代码,它正确完美。
public List<Details> filter(String search) {
TypedQuery<Details> query = em.createQuery("SELECT DISTINCT um FROM Details um INNER JOIN um.admin ad WHERE um.name like :search and ad.status =:status", Details.class );
String searchkey = search;
String status = "True";
query.setParameter("search", searchkey + '%');
query.setParameter("status", status);
return query.getResultList();
}
在Details类中包含名称为字符串。
public class Details implements Serializable {
@Column(name="name")
private String name;
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name ="id")
private List<Email> email= new ArrayList<Email>();
}
就像我想用搜索作为电子邮件一样,而不是名字我想使用电子邮件。现在我尝试下面的代码,但它显示错误。
public List<Details> filterEmail(String search) {
System.out.println("Email filtering query..");
TypedQuery<Details> query = em.createQuery("SELECT DISTINCT um FROM Details um INNER JOIN um.admin ad WHERE elements(um.email) like :search and ad.status =:status", Details.class );
String status = "True";
query.setParameter("search",'%' +search+ '%');
query.setParameter("status", status);
return query.getResultList();
}
我该如何使用?提前谢谢。
答案 0 :(得分:0)
为什么不像这样搜索您的电子邮件对象的邮件属性
SELECT DISTINCT um FROM Details um
INNER JOIN um.admin ad
WHERE ad.mailproperty like :search and ad.status =:status