繼續(xù)之前那個(gè)復(fù)習(xí),繼續(xù)那3張表,在此前已經(jīng)可以聯(lián)級(jí)插入數(shù)據(jù),現(xiàn)在來聯(lián)級(jí)檢索出3張表的數(shù)據(jù),假設(shè)要求查出名字為“lzj"的學(xué)生在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");
          并將結(jié)果返回給struts的jsp頁面:
          if(results!=null){
             HttpSession session=request.getSession();
                   session.setAttribute("results",results);
                   return mapping.findForward("ok");


          jsp頁面接受,使用struts標(biāo)簽:

           <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 閱讀(333) 評(píng)論(0)  編輯  收藏 所屬分類: 個(gè)人學(xué)習(xí)日記Hibernate
          主站蜘蛛池模板: 运城市| 洮南市| 长治市| 拉萨市| 黑山县| 伊金霍洛旗| 宿州市| 察隅县| 涿鹿县| 常山县| 汝城县| 邵阳县| 台山市| 江油市| 正宁县| 麦盖提县| 鄂托克前旗| 鲁山县| 开平市| 永城市| 偏关县| 尼勒克县| 资源县| 临邑县| 永年县| 邹城市| 蛟河市| 东方市| 大石桥市| 南江县| 兴和县| 湖北省| 富川| 泰来县| 夹江县| 武定县| 长宁区| 东海县| 孙吴县| 明溪县| 龙泉市|