繼續之前那個復習,繼續那3張表,在此前已經可以聯級插入數據,現在來聯級檢索出3張表的數據,假設要求查出名字為“lzj"的學生在3張表里的所有記錄。使用inner join操作。

          TstudentDAO:

            public List findall(String name){
            Session session =this.getSession();
            Transaction tx = null;
            Query query = session.createQuery("select t.name,t.email,s.name,tt.times from TStudent t join t.TSubjectses s join t.TTests tt where t.name=:name");
            query.setString("name", name);
            List result = query.list();
               List templist = new ArrayList();
               for (Iterator it = result.iterator();it.hasNext();){
                Object[] row=(Object[])it.next();
                Map mm = new HashMap();
                mm.put("name", (String)row[0]);
                mm.put("email", (String)row[1]);
                mm.put("sname", (String)row[2]);
                mm.put("times", (Integer)row[3]);
                templist.add(mm);
               }
               return templist;
              }


          action里只需要一句話:
          List results =  tstudentDAO.findall("lzj");
          并將結果返回給struts的jsp頁面:
          if(results!=null){
             HttpSession session=request.getSession();
                   session.setAttribute("results",results);
                   return mapping.findForward("ok");


          jsp頁面接受,使用struts標簽:

           <logic:present name="results">
               <table border="1">
              <logic:iterate id="element" name="results">
              <tr>
                <td width="100"><bean:write name="element" property="name"/></td>
             <td width="100"><bean:write name="element" property="email"/></td>
                <td width="100"><bean:write name="element" property="sname"/></td>
                      <td width="100"><bean:write name="element" property="times"/></td>

          <td id="result"></td>
             </tr>
          </logic:iterate>
           </logic:present>



          posted on 2008-06-26 23:10 lzj520 閱讀(328) 評論(0)  編輯  收藏 所屬分類: 個人學習日記Hibernate
          主站蜘蛛池模板: 郁南县| 南汇区| 绍兴市| 哈密市| 南阳市| 永寿县| 佛冈县| 盐津县| 六盘水市| 会同县| 内黄县| 奈曼旗| 嘉兴市| 芮城县| 家居| 龙南县| 壶关县| 内乡县| 新竹县| 吉水县| 静乐县| 进贤县| 自治县| 信阳市| 福贡县| 芮城县| 德清县| 宜阳县| 布拖县| 云林县| 南涧| 新河县| 寿阳县| 甘德县| 门头沟区| 静宁县| 隆昌县| 建湖县| 柳河县| 华坪县| 临安市|