vo包
Iaitem.java
- import java.util.Set;
- /**
- * @author
- * @version 创建时间:Jan 2, 2009 11:42:16 AM
- * 类说明
- */
- public class Iaitem {
- private int itemid;
- private String itemname;
- private int itemcode;
- //代表全部的子栏目
- private Set iasubitems;
- public int getItemid() {
- return itemid;
- }
- public void setItemid(int itemid) {
- this.itemid = itemid;
- }
- public String getItemname() {
- return itemname;
- }
- public void setItemname(String itemname) {
- this.itemname = itemname;
- }
- public int getItemcode() {
- return itemcode;
- }
- public void setItemcode(int itemcode) {
- this.itemcode = itemcode;
- }
- //
- public Set getIasubitems() {
- return iasubitems;
- }
- //
- public void setIasubitems(Set iasubitems) {
- this.iasubitems = iasubitems;
- }
- }
Iaitem.hbm.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse Persistence Tools
- -->
- <hibernate-mapping>
- <class name="com.123.mgzst.vo.Iaitem" table="IAITEM" schema="STMG">
- <id name="itemid" type="java.lang.Integer">
- <column name="ITEMID" precision="22"/>
- <generator class="sequence">
- <param name="sequence">STMG.item_id_seq</param> <!-- seq --> <!-- native--> <!-- native-->
- </generator>
- </id>
- <property name="itemname" type="java.lang.String">
- <column name="ITEMNAME" length="50" />
- </property>
- <property name="itemcode" type="java.lang.Integer">
- <column name="ITEMCODE" precision="22"/>
- </property>
- <!-- set -->
- <set name="iasubitems" inverse="true" cascade="all" table="IASUBITEM">
- <key>
- <column name="ITEMID" precision="22"/>
- </key>
- <one-to-many class="com.123.mgzst.vo.Iasubitem" /> <!-- one to many-->
- </set>
- </class>
- </hibernate-mapping>
Iasubitem.java
- public class Iasubitem {
- private int subid;
- private String subname;
- private int itemid;
- private int subcode;
- private Iaitem iaitem;
- public int getSubid() {
- return subid;
- }
- public void setSubid(int subid) {
- this.subid = subid;
- }
- public String getSubname() {
- return subname;
- }
- public void setSubname(String subname) {
- this.subname = subname;
- }
- public int getItemid() {
- return itemid;
- }
- public void setItemid(int itemid) {
- this.itemid = itemid;
- }
- public int getSubcode() {
- return subcode;
- }
- public void setSubcode(int subcode) {
- this.subcode = subcode;
- }
- public Iaitem getIaitem() {
- return iaitem;
- }
- public void setIaitem(Iaitem iaitem) {
- this.iaitem = iaitem;
- }
- }
Iasubitem.hbm.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
- <!--
- Mapping file autogenerated by MyEclipse Persistence Tools
- -->
- <hibernate-mapping>
- <class name="com.123.mgzst.vo.Iasubitem" table="IASUBITEM" schema="STMG">
- <id name="subid" type="java.lang.Integer">
- <column name="SUBID" precision="22"/>
- <generator class="sequence">
- <param name="sequence">STMG.subitem_id_seq</param>
- </generator>
- </id>
- <!-- many to one -->
- <many-to-one name="iaitem" class="com.123.mgzst.vo.Iaitem" fetch="select">
- <column name="ITEMID" precision="22"/>
- </many-to-one>
- <property name="subname" type="java.lang.String">
- <column name="SUBNAME" length="50" />
- </property>
- <property name="subcode" type="java.lang.Integer">
- <column name="SUBCODE" precision="22"/>
- </property>
- </class>
- </hibernate-mapping>
dao
IItemDAOImpl.java
- public class IItemDAOImpl extends HibernateDaoSupport implements IItemDAO {
- public List queryAll() throws Exception {
- // TODO Auto-generated method stub
- String hql = "FROM Iaitem AS i";
- List all = super.getSession().createQuery(hql).list();
- return all;
- }
- }
action
ItemAction.java
- public class ItemAction extends DispatchAction {
- private IItemDAO iitemdao;
- /*
- * Generated Methods
- */
- /**
- * Method execute
- * @param mapping
- * @param form
- * @param request
- * @param response
- * @return ActionForward
- */
- public ActionForward selectall(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- ItemForm itemForm = (ItemForm) form;// TODO Auto-generated method stub
- List all =null;
- try {
- all = this.iitemdao.queryAll();
- //Iterator
- Iterator iter = all.iterator(); //all是一个List
- while(iter.hasNext()) {
- Iaitem item = (Iaitem)iter.next();
- System.out.println(item.getItemname());
- Iterator it = item.getIasubitems().iterator(); /item.getIasubitems()
- while(it.hasNext()) {
- Iasubitem si = (Iasubitem)it.next();
- System.out.println("|- " + si.getSubname());
- }
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- request.setAttribute("all", all);
- return mapping.findForward("question");
- }
jsp
- <logic:iterate id="item" scope="request" name="all">
- ${item.itemname }<br>
- <logic:iterate id="subitem" name="item" property="iasubitems">
- |-${subitem.subname }<br>
- </logic:iterate>
- </logic:iterate>