繼續之前那個復習,繼續那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 閱讀(329) 評論(0)  編輯  收藏 所屬分類: 個人學習日記 、Hibernate
          主站蜘蛛池模板: 石林| 绥棱县| 泸水县| 城口县| 武宁县| 紫云| 樟树市| 城固县| 柯坪县| 繁昌县| 新巴尔虎左旗| 互助| 平果县| 会昌县| 丰镇市| 和平区| 湄潭县| 瑞安市| 喀什市| 洛阳市| 屏东市| 盐边县| 永清县| 绵竹市| 望都县| 莲花县| 措美县| 承德市| 荆门市| 大邑县| 伊金霍洛旗| 子长县| 蒙自县| 峨边| 阜新| 铜川市| 黄平县| 嘉兴市| 绥化市| 大安市| 昌吉市|