select t.id,t.name,b.num from producttype_t t left join ( select count(id) as num,type as type from product_t group by type ) b on b.type = t.id

解决方案 »

  1.   

    hql 支持链接查询,你这个可以直接把对应的表换成对象  就可以使用了。
      

  2.   

    刚查到了……是用List<>这样的吧……但是在JSP页面的时候,EL表达式又出错了
    The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
    这样选出来的id为什么类型啊?
      

  3.   

    这是个分页 
    String queryCountHql = "select t.id,t.name,b.num from producttype_t t left join ( select count(id) as num,type as type from product_t group by type ) b on b.type = t.id";      
            List<Producttype> data = getSession().createSQLQuery(queryCountHql)   
                        .setFirstResult(pageroffset)   
                        .setMaxResults(pageSize)   
                        .list();   
            //得到结果集   
            PageModel pm = new PageModel();     
            pm.setData(data); 
      

  4.   

    <c:forEach items="${pm.data}" var="data" varStatus="status">
       <pg:item>
         <tr <c:if test="${status.count%2 == 0 }">class="even"</c:if>
    <c:if test="${status.count%2 == 1 }">class="odd"</c:if>>
    <td>
        ${data.id }
    </td>
    <td>
      <a href="<c:url value='/back/sysProductInfo.do?method=showProductInfoByType&id=${producttype.id }'/>">${producttype.name }</a>
    </td>
    <td>
       ${producttype.num }
            </td>
    <td>
    <a href="<c:url value='/back/sysProducttype.do?method=forwardUpdate&id=${producttype.id }' />">编辑</a>
    </td>
    </tr>
    </pg:item>

    </c:forEach>