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
这个错误。

解决方案 »

  1.   

    <logic:iterate id=" " name="libraryList">
       <bean:write name="  " property="location"/> 
    </logic:iterate>
    用这个标签包起来 
    logic里面的id值=bean里面的name值
      

  2.   

    libraryList是个集合,你怎么着也得去遍历一下,然后取单个元素的属性吧
    <c:forEach items="libraryList" var="library">
        <bean:write name="library" property="name"/> 
    </c:forEach>
      

  3.   


    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 
    这个错误。 
      

  4.   

    LibraryDAOpublic List getLibrary()
    {
    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 
    这个错误。 
      

  5.   

    HQL语句问题。
    检查下PO中是否有name,spec,unit等的属性。
      

  6.   

    logic:iterate id="libraryList" name="libraryList"> 
    ID 和NAME 可以相同吗?
      

  7.   


    你logic里面id是bean里面的library 不是list 这个id=bean write里面的name
      

  8.   


    这个id是和bean write里面的name一样   id是library bean里面的
      

  9.   

    你先测测libraryList中是否有值,如果没有,应该是HQL的问题!如果有,先看看你的实体类的set,get方法正确否,然后再看jsp页面!
      

  10.   


    这个要怎么样子来测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中是否有值?
      

  11.   

    自己顶一下。这个问题已经弄了我很久了。现在还没有解决。也看了hibernate的文档,hql语句是没有写错的。现在是bean:write显示不出那结果,除了bean wite还有其它的方法来显示出那查询的结果吗?
      

  12.   

    你po类里看下,估计没写GET,SET方法, 每个property属性要对应一个get,set方法,而且名字要跟property属性后面的值要一样
      

  13.   

    select name,spec,unit,sum(amount),avg(price),location from Library group by location 
    这样你用了聚合函数,POJO中就没有对应sum(amount),avg(price)的属性,就没有GET,SET方法!这样肯定不行啊!
    核心标签,STRUTS标签都是根据GET方法来取值!你试下只取name,spec,unit,location (这些在POJO中GET方法总有把)
    肯定能够成功!
      

  14.   

    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;
    }
    我都写了。但还是不行啊!
      

  15.   


    你这个想法,我也有想过,我也有说去把sum(amount),avg(price)这两个删了,但还是不行,首先提示的就是name不行,我把name删除掉,下个就提示说spec不行。总之所有的都不行。我现在很郁闷。。如果我把HQL换成“from Library”,这个是最简单的,这样子就可以了。但是我现在的hql也不会有错啊!我有去看hibernate文档的。
      

  16.   

    libraryList 这个里面放的啥对象啊! 貌似是这个对象里没有提供get/set方法
      

  17.   

    放查询出来的。
    下面是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;
        }
      

  18.   

    缺少某个属性的get set方法,还有就是group by后面要name,spec,unit这些字段吧 ,sql中没有这些字段都会报错啊
      

  19.   

    在Action里用System.out.println()验证下PO里的值看是否有????
    还有我认为就算name,spec,unit有值,但sum(amount),avg(price)应该没值,你的PO里没这些字段来装这些值吧?
    我有个问题:
    select name,spec,unit,sum(amount),avg(price),location from Library group by location 
    返回的不是Object[]吗??
    小弟刚学校毕业出来....
    不对之处请口下留人
      

  20.   


    我也是刚从学校毕业出来你说在Action里用System.out.println()验证下PO里的值看是否有???? 
    这个怎么样子用请教一下。我不知道在System.out.println()这里填入什么。我把sum(amount),avg(price)这两个去掉了,还是一样子,还是不行。报同样的错误 。后来我发现,只要我用了select去查询的都不行。如果我用from Library这样子就可以。请问像这样子的问题,要怎么样子来解决。
      

  21.   

    怎么没有遇到跟我一样子的问题吗?后来我发现,只要我用了select去查询的都不行。如果我用from Library这样子就可以。请问像这样子的问题,要怎么样子来解决。
      

  22.   

    你把hql语句打出来拿到数据库那边去执行一下,如果那边有错,就是hql语句问题,如果正常应当是没有libraryList的set/get方法吧。
    你发了两个一样的帖子。
      

  23.   


    嗯。是的。我的hql拿到数据库那边执行过,没有错误,能查询出我要的东西。还有,我的bean里也有set/get方法。
      

  24.   

    hql 用select返回的list中,每个条目都是String类型的数据,而不是Library 对象的属性, 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;
    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; 
      

  25.   


    按照你的方法,我可以打印出来那现在这样子打印出来了后,也就说明我的HQL是不会有问题的。那怎么我的显示不行?我的get方法也有。
      

  26.   


    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查询的结果 ,但怎么样子在页面上显示出来呢?