select name,spec,unit,sum(amount),avg(price),location from Library group by location这句HQL语句有错吗?错的话要怎么样子来修改。还有,没有错的话。
怎么我用
<bean:write name="libraryList" property="name"/>
<bean:write name="libraryList" property="spec"/>
<bean:write name="libraryList" property="unit"/>
<bean:write name="libraryList" property="sum(amount)"/>
<bean:write name="libraryList" property="avg(price)"/>
<bean:write name="libraryList" property="location"/>显示的时候出现
No getter method for property name of bean libraryList
这个错误。
怎么我用
<bean:write name="libraryList" property="name"/>
<bean:write name="libraryList" property="spec"/>
<bean:write name="libraryList" property="unit"/>
<bean:write name="libraryList" property="sum(amount)"/>
<bean:write name="libraryList" property="avg(price)"/>
<bean:write name="libraryList" property="location"/>显示的时候出现
No getter method for property name of bean libraryList
这个错误。
解决方案 »
- 求助了。Spring动态定时器。。。
- spring+hibernate整合报错
- ibatis
- AXIS2的Web Service服务端,用xfire客户端调用报“Could not find a service to invoke.”
- jstl标签 变量的赋值回车字符问题
- struts2 验证框架中,如果要验证一组值该如何写xml。
- Hibernate新手问题:将string类型的映射为hbm文件的id时,应该使用哪种<generator class=> ??而使得在添加操作时可以给出要添加的值?
- 请帮帮忙...请问如何用Java读取串行接口传来的数据?
- ActionForm绑定对象?
- getHibernateTemplate() 操作数据库事务回滚不了,求救。
- 高人给指点下思路!
- 关于框架重量级别的定义的请教
<bean:write name=" " property="location"/>
</logic:iterate>
用这个标签包起来
logic里面的id值=bean里面的name值
<c:forEach items="libraryList" var="library">
<bean:write name="library" property="name"/>
</c:forEach>
LibraryDAO ldao = new LibraryDAO();
List library = ldao.getLibrary();
HttpSession httpSession = request.getSession();
httpSession.setAttribute("libraryList", library);
在JSP页面上
<logic:notEmpty name="libraryList">
<logic:iterate id="libraryList" name="libraryList">
<tr height="25">
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="name"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="spec"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="unit"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="sum(amount)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="avg(price)"/></td>
<td align="center" bgcolor="#FFFFCC"><bean:write name="libraryList" property="location"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>我是这样子写的,但就是出现No getter method for property name of bean libraryList
这个错误。
{
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();
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="libraryList" name="libraryList">
<tr height="25">
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="name"/> </td>
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="spec"/> </td>
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="unit"/> </td>
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="sum(amount)"/> </td>
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="avg(price)"/> </td>
<td align="center" bgcolor="#FFFFCC"> <bean:write name="libraryList" property="location"/> </td>
</tr>
</logic:iterate>
</logic:notEmpty> 我是这样子写的,但就是出现No getter method for property name of bean libraryList
这个错误。
检查下PO中是否有name,spec,unit等的属性。
ID 和NAME 可以相同吗?
你logic里面id是bean里面的library 不是list 这个id=bean write里面的name
这个id是和bean write里面的name一样 id是library bean里面的
这个要怎么样子来测libraryList中是否有值?值应该是有了的。
我把<bean:write name="libraryList" property="name"/>
<bean:write name="libraryList" property="spec"/>
<bean:write name="libraryList" property="unit"/>
<bean:write name="libraryList" property="sum(amount)"/>
<bean:write name="libraryList" property="avg(price)"/>
<bean:write name="libraryList" property="location"/>
这些删除了。在页面上有两行空的出来。说明是有值了,但就是用我的这样子就是显示不出来。
这个是我自己估计的。你现在告诉我要怎么样子来测libraryList中是否有值?
这样你用了聚合函数,POJO中就没有对应sum(amount),avg(price)的属性,就没有GET,SET方法!这样肯定不行啊!
核心标签,STRUTS标签都是根据GET方法来取值!你试下只取name,spec,unit,location (这些在POJO中GET方法总有把)
肯定能够成功!
return this.libraryid;
} public void setLibraryid(Integer libraryid) {
this.libraryid = libraryid;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} public String getSpec() {
return this.spec;
} public void setSpec(String spec) {
this.spec = spec;
} public String getUnit() {
return this.unit;
} public void setUnit(String unit) {
this.unit = unit;
} public Float getAmount() {
return this.amount;
} public void setAmount(Float amount) {
this.amount = amount;
} public Float getPrice() {
return this.price;
} public void setPrice(Float price) {
this.price = price;
} public Date getIntime() {
return this.intime;
} public void setIntime(Date intime) {
this.intime = intime;
} public Date getTime() {
return this.time;
} public void setTime(Date time) {
this.time = time;
} public String getUsername() {
return this.username;
} public void setUsername(String username) {
this.username = username;
} public String getLocation() {
return this.location;
} public void setLocation(String location) {
this.location = location;
}
我都写了。但还是不行啊!
你这个想法,我也有想过,我也有说去把sum(amount),avg(price)这两个删了,但还是不行,首先提示的就是name不行,我把name删除掉,下个就提示说spec不行。总之所有的都不行。我现在很郁闷。。如果我把HQL换成“from Library”,这个是最简单的,这样子就可以了。但是我现在的hql也不会有错啊!我有去看hibernate文档的。
下面是get/set方法public Integer getLibraryid() {
return this.libraryid;
} public void setLibraryid(Integer libraryid) {
this.libraryid = libraryid;
} public String getName() {
return this.name;
} public void setName(String name) {
this.name = name;
} public String getSpec() {
return this.spec;
} public void setSpec(String spec) {
this.spec = spec;
} public String getUnit() {
return this.unit;
} public void setUnit(String unit) {
this.unit = unit;
} public Float getAmount() {
return this.amount;
} public void setAmount(Float amount) {
this.amount = amount;
} public Float getPrice() {
return this.price;
} public void setPrice(Float price) {
this.price = price;
} public Date getIntime() {
return this.intime;
} public void setIntime(Date intime) {
this.intime = intime;
} public Date getTime() {
return this.time;
} public void setTime(Date time) {
this.time = time;
} public String getUsername() {
return this.username;
} public void setUsername(String username) {
this.username = username;
} public String getLocation() {
return this.location;
} public void setLocation(String location) {
this.location = location;
}
还有我认为就算name,spec,unit有值,但sum(amount),avg(price)应该没值,你的PO里没这些字段来装这些值吧?
我有个问题:
select name,spec,unit,sum(amount),avg(price),location from Library group by location
返回的不是Object[]吗??
小弟刚学校毕业出来....
不对之处请口下留人
我也是刚从学校毕业出来你说在Action里用System.out.println()验证下PO里的值看是否有????
这个怎么样子用请教一下。我不知道在System.out.println()这里填入什么。我把sum(amount),avg(price)这两个去掉了,还是一样子,还是不行。报同样的错误 。后来我发现,只要我用了select去查询的都不行。如果我用from Library这样子就可以。请问像这样子的问题,要怎么样子来解决。
你发了两个一样的帖子。
嗯。是的。我的hql拿到数据库那边执行过,没有错误,能查询出我要的东西。还有,我的bean里也有set/get方法。
List library=query.list;
Iterator it =library.iterator();
while(it.hasNext()){
Object[] results =(Object[])it.next();
----打印看看
System.out.println(results[0]);
System.out.println(results[0]);
}
HibernateSessionFactory.closeSession();
return library;
按照你的方法,我可以打印出来那现在这样子打印出来了后,也就说明我的HQL是不会有问题的。那怎么我的显示不行?我的get方法也有。
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查询的结果 ,但怎么样子在页面上显示出来呢?