此查询在控制台上正常运行,但现在我想在xhtml
的{{1}}页面中显示它,我试过这个dataTable
但是它无法正常工作
attemp
file.xhtml
List<Object[]> results;
public List<Object[]> getResults() {
results = entityManager.createQuery("select d.lib_naturepanne,count(r) as nbrr"+" from NaturePanne d JOIN d.listReparation r GROUP BY d.lib_naturepanne").getResultList();
for (Object[] result : results) {
String name = (String) result[0];
int count = ((Number) result[1]).intValue();
System.out.println("name "+name+ " count "+count);
}
return results;
答案 0 :(得分:1)
#{rep.results.name}
错了。您有一个List<Object[]>
,因此您可以得到如下结果:#{rep[0]}
或者将您的Object []映射到某种POJO。
public class NameCount {
String name;
int count;
public NameCount(Object[] o) {
name = (String) o[0];
count = (Integer) o[1];
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public List<NameCount> getResults() {
List<Object[]> results = entityManager.createQuery(...);
List<NameCount> rowset = new ArrayList<NameCount>();
for (Object[] o : results) {
rowset.add(new NameCount(o));
}
return rowset;
}