LibraryDAO.javapublic List getLibrary()
{
tx=session.beginTransaction();
Query query=session.createQuery("select library.name,library.spec,library.unit,sum(library.amount),avg(library.price),library.location from Library library group by library.location");
List library=query.list();
tx.commit();
HibernateSessionFactory.closeSession();
return library;
}LibraryDAO ldao = new LibraryDAO();
List library = ldao.getLibrary();
HttpSession httpSession = request.getSession();
httpSession.setAttribute("libraryList", library);
在JSP页面上
<logic:notEmpty name="libraryList">
<logic:iterate id="library1" name="libraryList">
<tr height="25">
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="name"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="spec"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="unit"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="sum(amount)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="avg(price)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="location"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>为什么会出错。显示的时候出现
No getter method for property name of bean libraryList
这个错误。 除了用bean write方法显示,还可以用其它的方法吗?各位大侠帮帮忙,,小弟十分的感激
{
tx=session.beginTransaction();
Query query=session.createQuery("select library.name,library.spec,library.unit,sum(library.amount),avg(library.price),library.location from Library library group by library.location");
List library=query.list();
tx.commit();
HibernateSessionFactory.closeSession();
return library;
}LibraryDAO ldao = new LibraryDAO();
List library = ldao.getLibrary();
HttpSession httpSession = request.getSession();
httpSession.setAttribute("libraryList", library);
在JSP页面上
<logic:notEmpty name="libraryList">
<logic:iterate id="library1" name="libraryList">
<tr height="25">
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="name"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="spec"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="unit"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="sum(amount)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="avg(price)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="library1" property="location"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>为什么会出错。显示的时候出现
No getter method for property name of bean libraryList
这个错误。 除了用bean write方法显示,还可以用其它的方法吗?各位大侠帮帮忙,,小弟十分的感激
你这里的 library 是list的呀,你应该 这样写,类似下面的写法
httpSession.setAttribute("libraryList", library.toCharArray(new LibraryBean[0]));
property="avg(price)"
这样写不对的。记得这个bean就是对应你的form。需要里面的set get方法
现在是sum和avg 自然没有那个对应的配置太久不用struct1.2了
<%
List<Object[]> useraccountList = (List)request.getAttribute("list"); for(Object[] obj : useraccountList)
{%>
<tr height="25">
<td align="center" bgcolor="#FFFFCC"> <%=obj[1]%> </td>
<td align="center" bgcolor="#FFFFCC"> <%=obj[2]%> </td>
<td align="center" bgcolor="#FFFFCC"> <%=obj[3]%> </td>
<td align="center" bgcolor="#FFFFCC"> <%=obj[4]%> </td>
<td align="center" bgcolor="#FFFFCC"> <%=obj[5]%> </td>
<td align="center" bgcolor="#FFFFCC"> <%=obj[6]%> </td>
</tr> <%}%>
未找到这个豆子的这个参数的getter方法??
我把sum(amount),avg(price)这两个去了,都还是一样子。
我把hql改为select name,spec,location from Library;
这样子都还不行。
只要用from Library这样子就没有问题。
谁知道这样子的问题要怎么样子来解决的。
{
tx=session.beginTransaction();
Query query=session.createQuery("select library.name,library.spec,library.unit,sum(library.amount),avg(library.price),library.location from Library library group by library.location");
List library=query.list();
tx.commit(); List librarys=new ArrayList(); for(int i=0;i<list.size();i++){
Object[] obs=list.get(i)
libraryList library=new libraryList();
library.setName=(String)obs[0];
library.setSpec=(String)obs[1];
................//对了你的PO应该没有对应sum(library.amount),avg(library.price)值的字段,建议定义两个出来.
}
HibernateSessionFactory.closeSession();
return library;
}
网吧上着玩..没工具,就在回复框编辑的..不知道对不对?
有啊!name,spec,unit,location都有get方法
用select,返回的是一个标量的结果集,就是一个集合,里面每条数据是一个数组请学习一下hibernate的基础吧
这个我知道。我现在就是要得到select结果集。
LibraryDAO ldao = new LibraryDAO();
List<Object> library = ldao.getLibrary();
HttpSession httpSession = request.getSession();
httpSession.setAttribute("libraryList", library);红色处加上你的类名
<bean:write name="library1" property="别名"/>
LibraryDAO ldao = new LibraryDAO();
List library = ldao.getLibrary();
Iterator it =library.iterator();
while(it.hasNext())
{
Object[] results =(Object[])it.next();
System.out.println("****************************");
System.out.println(results[0]);
System.out.println(results[1]);
System.out.println(results[2]);
System.out.println(results[3]);
System.out.println(results[4]);
System.out.println(results[5]);
System.out.println("============================");
我这里可以打印出我的hql里查询的结果。但我怎么样子在页面上显示出这些结果呢?