struts2一对多遍历问题hibernate
//actionpublic class UserAction extends ActionSupport{
UserService userService;
NoteService noteService;
List listUser;
List listNode;
User user;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List getListUser() {
return listUser;
}
public void setListUser(List listUser) {
this.listUser = listUser;
}
public List getListNode() {
return listNode;
}
public void setListNode(List listNode) {
this.listNode = listNode;
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
public NoteService getNoteService() {
return noteService;
}
public void setNoteService(NoteService noteService) {
this.noteService = noteService;
}
public String listUser(){
listUser=userService.findAllUser();
Iterator it=listUser.iterator();
while(it.hasNext()){
User temp=(User)it.next();
listNode=noteService.findByUserId(temp.getUserid());
System.out.println("------------------------>"+listNode.size());
temp.setListNote(listNode);
}
return "list_user";
}
}
//daoImpl
public List findAllUser() {
// TODO Auto-generated method stub
return this.getHibernateTemplate().find(" from User");
}
public List findByUserId(Integer id) {
// TODO Auto-generated method stub
List list=new ArrayList();
try {
list=this.getHibernateTemplate().find(" from Note n where n.noteid='"+id+"'");
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return list;
}
//xml
<set name="notes" inverse="true">
<key>
<column name="userid" />
</key>
<one-to-many class="com.test.vo.Note" />
</set>
<many-to-one name="user" class="com.test.vo.User" fetch="select">
<column name="userid" />
</many-to-one>
//jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<body>
This is user JSP page. <br>
<tr>
<td>用户标识</td>
<td>用户名</td>
<td>密码</td>
<td>评论</td>
<td>评价</td>
</tr>
<s:iterator value="#listUser" id="user">
<tr>
<td><s:property value="userid"/></td>
<td><s:property value="username"/></td>
<td><s:property value="password"/></td>
</tr>
<s:iterator value="#user.listNode" id="note">
<tr>
<td><s:property value="content"/></td>
<td><s:property value="info"/></td>
</tr>
</s:iterator>
</s:iterator>
</body>
问题:
望各位大侠帮帮忙了 请指教
为什么列表jsp没有东西
也查数据库了,就是列表没数据
列表用户下面的评论也出不来啊
搞了两天了 纠结中。。。。。 --------------------编程问答--------------------
<s:iterator value="accountList" var="account">
<tr>
<td>
<s:property value="#account[0]" />
</td>
accountList 是action中list var是自己定义的
然后list中有几列就从0开始遍历 --------------------编程问答-------------------- User.java
private Integer userid;
private String username;
private String password;
Note.java
private String content;
private String info;
<s:iterator value="listUser" var="user">
<tr>
<td><s:property value="#user[0]"/></td>
<td><s:property value="#user[1]"/></td>
<td><s:property value="#user[2]"/></td>
</tr>
<s:iterator value="listNode" var="note">
<tr>
<td><s:property value="#note[0]"/></td>
<td><s:property value="#note[1]"/></td>
</tr>
</s:iterator>
</s:iterator>
还是不行啊 是个空列表 从0依次开始 怎么找到各自的属性 空列表
望大侠解析啊 怎么列出数据呢 --------------------编程问答-------------------- 使用struts2标签库中的Iterator 标签直接遍历
补充:Java , J2ME