<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 325,  comments - 25,  trackbacks - 0
    1.定義MyHibernateDaoSupport 擴(kuò)展HibernateSupport

    mport java.sql.SQLException;
    import java.util.List;

    import org.hibernate.HibernateException;
    import org.hibernate.Query;
    import org.hibernate.Session;
    import org.springframework.orm.hibernate3.HibernateCallback;
    import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

    public class MyHibernateDaoSupport extends HibernateDaoSupport {
     public List findByPage(final String hql,final int offset,final int pageSize)
     {
      List list=this.getHibernateTemplate().executeFind(new HibernateCallback()
      {
       public Object doInHibernate(Session session)
         throws HibernateException, SQLException {
        List result=session.createQuery(hql).setFirstResult(offset).setMaxResults(pageSize).list();
        return result;
       }
      }
      );
      return list;
     }
     public List findByPage(final String hql,final String value,final int offset,final int pageSize)
     {
      List list=this.getHibernateTemplate().executeFind(new HibernateCallback()
      {
       public Object doInHibernate(Session session)
         throws HibernateException, SQLException {
        List result=session.createQuery(hql).setParameter(0,value).setFirstResult(offset).setMaxResults(pageSize).list();
        return result;
       }
      }
      );
      return list;
     }
     public List findByPage(final String hql,final Object[] values,final int offset,final int pageSize){
      List list=this.getHibernateTemplate().executeFind(new HibernateCallback()
      {
       public Object doInHibernate(Session session)
         throws HibernateException, SQLException {
        Query query=session.createQuery(hql);
        for(int i=0;i<values.length;i++)
        {
         query.setParameter(i,values[i]);
        }
        List result=query.setFirstResult(offset).setMaxResults(pageSize).list();
        return result;
       }
      }
      );
      return list;
     }
    }


    2.定義要分頁(yè)的實(shí)體的Dao接口
    如:
    public interface StudentDao {
     Student get(int id);
     void save(Student student);
     void update(Student student);
     void delete(int id);
     void delete(Student student);
     List<Student> findAll();
     List<Student> findAllByPage(int pageNo,int pageSize);
     int getStudentCount();

     List<Student> findStudentByNameAndNumber(String stuName,String stuNumber);
    }
    3.定義實(shí)現(xiàn)類
    主要寫出兩個(gè)分頁(yè)中要用到的方法
    public List<Student> findAllByPage(int pageNo, int pageSize) {
      if(pageNo<1){
       return null;
      }
      int offset=(pageNo-1)*pageSize;
      return findByPage("from Student", offset, pageSize);
     }
     public int getStudentCount() {
      List<Student> listStudent=this.getHibernateTemplate().find("from Student");
      return listStudent.size();
     }

    4.定義Service接口
    public interface ExamService {
     int STUDENT_PAGE_SIZE=3;
     int QUESTION_PAGE_SIZE=3;
     int addStudent(String stuNumber,String name,String className,String humanId,String email,String address,String phone) throws Exception;
     void deleteStudent(int id) throws Exception;
     List<Student> listStudent(int pageNo) throws Exception;
     int addQuestion(String quTitle,String quHard,String quScore,String quAnswer,String quType,String selectOption,int typeid) throws Exception;
     void deleteQuestion(int id) throws Exception;
     List<Question> listQuestion(int pageNo) throws Exception;
     void deleteExamtype(int typeid) throws Exception;
     int addExamtype(String textName,String testTime)throws Exception;
     List<Examtype> getAllExamtype()throws Exception;
     boolean adminLogin(String admName,String admPwd)throws Exception;
     int getStudentCount()throws Exception;
     int getQuestionCount()throws Exception;
     int getPageCount(int count,int pageSize);
     String studentLogin(String stuName,String stuNumber)throws Exception;
     Question getNextQuestion(List<Integer> alreadys,int typeid)throws Exception;
     Question getQuestionById(int id)throws Exception;
     String getExamtypeName(int typeid)throws Exception;;
    }
    5.定義實(shí)現(xiàn)類
    public int getPageCount(int count, int pageSize) {
      return (count+pageSize-1)/pageSize;
     }
    public int getStudentCount() throws Exception {
      return studentDao.getStudentCount();
     }

    public List<Student> listStudent(int pageNo) throws Exception {

      return studentDao.findAllByPage(pageNo, STUDENT_PAGE_SIZE);

     }

    6.ListStudentAction.java
    int studentCount=examService.getStudentCount();
      ActionMessages errors=new ActionMessages();
      if(studentCount<1)
      {
       errors.add("studentCount",new ActionMessage("studentCount.null"));
       mapping.findForward("success");
      }
      int pageCount=examService.getPageCount(studentCount,examService.STUDENT_PAGE_SIZE);
      int pageNo;
      if(request.getParameter("pageNo")==null || request.getParameter("pageNo").trim().equals(""))
      {
       pageNo=1;
      }
      try {
       pageNo=Integer.parseInt(request.getParameter("pageNo").trim());
      } catch (Exception e) {
       pageNo=1;
      }
      if(pageNo>pageCount){
       pageNo=pageCount;
      }
      request.setAttribute("pageCount",pageCount);
      request.setAttribute("currentPage",pageNo);
      request.setAttribute("studentList", examService.listStudent(pageNo));
      return mapping.findForward("success");
    7.listStudent.jsp

    <table cellspacing="0" cellpadding="0" border="1" width="700">
      <tr>
       <th>
        <bean:message key="student.shenfenzheng" />
       </th>
       <th>
        <bean:message key="student.mingzi" />
       </th>
       <th>
        <bean:message key="student.banji" />
       </th>
       <th>
        <bean:message key="student.xuehao" />
       </th>
       <th>
        <bean:message key="student.youjian" />
       </th>
       <th>
        <bean:message key="student.dianhua" />
       </th>
       <th>
        <bean:message key="student.address" />
       </th>
       <th>
        <bean:message key="student.isdelete" />
       </th>
      </tr>
      <c:forEach items="${requestScope.studentList}" var="students">
       <tr>
        <td align="center">
         ${students.humanId}
        </td>
        <td align="center">
         ${students.stuName}
        </td>
        <td align="center">
         ${students.stuClassName}
        </td>
        <td align="center">
         ${students.stuNumber}
        </td>
        <td align="center">
         ${students.email}
        </td>
        <td align="center">
         ${students.phone}
        </td>
        <td align="center">
         ${students.address}
        </td>
        <td align="center">
         <a href="deleteStudent.do?delStuid=${students.id}"
          onclick='return confirm("<bean:message key="confirm.del.student"/>");' target="center"><bean:message
           key="student.delete" />
         </a>
        </td>
       </tr>
      </c:forEach>
      <br />
      <tr>
       <td colspan="7" align="center">
        第${requestScope.currentPage}頁(yè) &nbsp;共${requestScope.pageCount}頁(yè)
        <a href="listStudent.do?pageNo=1">首頁(yè)</a>&nbsp;
        <logic:greaterThan value="1" name="currentPage" scope="request">
         <a href="listStudent.do?pageNo=${requestScope.currentPage-1}">
        </logic:greaterThan>
        上一頁(yè)
        <logic:greaterThan value="1" name="currentPage" scope="request">
         </a>
        </logic:greaterThan>

        <logic:lessThan value="${requestScope.pageCount}" name="currentPage"
         scope="request">
         <a href="listStudent.do?pageNo=${requestScope.currentPage+1}">
        </logic:lessThan>
        下一頁(yè)
        <logic:lessThan value="${requestScope.pageCount}" name="currentPage"
         scope="request">
         </a>
        </logic:lessThan>
        <a href="listStudent.do?pageNo=${requestScope.pageCount}">尾頁(yè)</a>&nbsp;
       </td>
      </tr>
     </table>

    posted on 2008-05-20 16:57 長(zhǎng)春語(yǔ)林科技 閱讀(4514) 評(píng)論(0)  編輯  收藏 所屬分類: hibernate
    <2008年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

     

    長(zhǎng)春語(yǔ)林科技?xì)g迎您!

    常用鏈接

    留言簿(6)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    相冊(cè)

    收藏夾

    搜索

    •  

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 国产精品美女自在线观看免费| 亚洲午夜免费视频| 日本免费高清一本视频| 久久精品国产亚洲av麻豆图片| 久久国产精品一区免费下载| 久久久久无码精品亚洲日韩| 成人精品一区二区三区不卡免费看| 亚洲色一色噜一噜噜噜| 一级做a爰片久久毛片免费看 | 看亚洲a级一级毛片| 久久精品a一国产成人免费网站 | a级毛片免费观看在线| 国产成人高清亚洲| 中文字幕免费在线视频| 亚洲av无码一区二区乱子伦as| 中文字幕免费不卡二区| 亚洲精品无码久久久久久久 | 小说区亚洲自拍另类| 亚洲高清视频一视频二视频三| 一级毛片免费全部播放| 亚洲国产精品福利片在线观看| 99久久免费精品高清特色大片| 亚洲毛片免费观看| 国产视频精品免费| 国产精品无码免费专区午夜 | 免费人成大片在线观看播放电影| 亚洲成a人片在线播放| 一区二区三区无码视频免费福利| 亚洲美女精品视频| 国产成人无码免费视频97| 两性色午夜免费视频| 亚洲国产情侣一区二区三区| 国产人妖ts在线观看免费视频| 国产精品偷伦视频免费观看了 | 亚洲www77777| 亚洲一级片免费看| 免费v片在线观看视频网站| 国产精品亚洲天堂| 亚洲无线电影官网| 国产91在线免费| 99久久免费观看|