下面的类我用的是hibernate自动映射生成的。
Reply表
private Integer rid;
private Topic topic;
private User user;
private Date rcdate;
private String rcontent;
private String rtitle;Section表
private Integer sid;
private User user;
private String sdesc;
private String sname;
private Set topics = new HashSet(0);
private Set topics_1 = new HashSet(0);Topic表
        private Integer tid;
private Section section;
private User user;
private Date tcdate;
private String tcontent;
private String ttitle;
private Set replies = new HashSet(0);
private Set replies_1 = new HashSet(0);User表:
         private Integer uid;
private String name;
private String uname;
private String upwd;
private String uemail;
private String img;
private Date createDate;
private Integer flag;
private Set topics = new HashSet(0);
private Set replies = new HashSet(0);
private Set sections = new HashSet(0);
private Set topics_1 = new HashSet(0);
private Set sections_1 = new HashSet(0);
private Set replies_1 = new HashSet(0);我想查出频道名称,频道描述。主题贴数。回复贴数。版主。
这是我的sql语句:
SELECT (select sname from section where sid=topic.s_id) 频道名称,(select sdesc from section where sid=topic.s_id) 频道描述, COUNT(*) 主题贴数,(select count(*) from reply where t_id=topic.tid and u_id=topic.u_id) 回复贴数,(select name from user where uid=topic.u_id) 版主 from topic GROUP BY  s_id,u_id如果我要把它转化成hql语句又该怎么写。即使我用sql语句写。因为得到的是个List结果集。我已经通过struts2的action放入到了request。因为没有对应的javabean。在jsp页面不知道如何用迭代标签输出。struts2标签或jstl标签都可以。在线等。今晚结贴。不管有没有满意的答案。

解决方案 »

  1.   

    即使我用sql语句写。因为得到的是个List结果集。我已经通过struts2的action放入到了request。因为没有对应的javabean。在jsp页面不知道如何用迭代标签输出。struts2标签或jstl标签都可以
    回答你这个问题,既然拿到了list,后台打印一下,就可以知道里边数据的格式,一般存在的格式是key:value的形式,比如userName:"mei",再request.setAttribute("key",list);
    页面<c:forEach item = "key" var = "param">
    ${param.userName}
    </c:forEach>
    用jstl标签可以遍历
      

  2.   

    第2个问题解决了。你说的list要是在查询出的列是属于某个javabean的属性才可以。
    我这个得到的结果是多张表的列组成的。而我的javabean都对应的是一张表。我是采用了数组输出。