`
brimstone
  • 浏览: 29408 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

struts hibernate spring 实现分页、排序、复杂条件查询①

    博客分类:
  • J2EE
阅读更多

2个月前,因为项目需要开始接触到SSH ,以前只用过JSP 开发过项目,所以对于SSH 一切都是新鲜玩意,虽然学习的过程是痛苦的,但是解决问题的快乐只有自己能体会到。
在这里是我第一次写Blog,一是为了能够和这里的朋友共同进步,二是为了记录自己收获的点点滴滴,三是为了能够给和我一样的初学者分享所得——严重跑题。。 :D

言归正传,下面是我的实现方法


一、开发环境
JDK1.5 Hibernate 3.1 Struts 1.2 Spring2.0 MyEclplise 5.5GA

二、Struts 和 Spring配置
 Struts配置文件

xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <!---->>  
  3.   
  4. <struts-config>  
  5.     <data-sources />  
  6.     <form-beans>  
  7.     <form-bean name="drugForm" type="com.trade.struts.form.DrugForm" />  
  8.     <form-bean name="drugQueryForm" type="com.trade.struts.queryform.DrugQueryForm" />  
  9.     <form-bean name="baseForm" type="com.trade.struts.queryform.BaseForm" />  
  10.     form-beans>  
  11.   
  12.     <global-exceptions />  
  13.     <global-forwards />  
  14.     <action-mappings>  
  15.     <action  
  16.       attribute="drugQueryForm"  
  17.       input="/Drug/drug_list.jsp"  
  18.       name="drugQueryForm"  
  19.       parameter="method"  
  20.       path="/drugQuery"  
  21.       scope="request"  
  22.       >  
  23.       <forward name="success" path="/index.jsp" />  
  24.       <forward name="list" path="/Drug/drug_list.jsp" />  
  25.     action>  
  26.                
  27.     action-mappings>  
  28.        
  29.     <!---->  
  30.     <controller>  
  31.         <set-property property="processorClass"  
  32.             value="org.springframework.web.struts.DelegatingRequestProcessor" />  
  33.     controller>  
  34.        
  35.     <!---->  
  36.     <message-resources parameter="com.trade.struts.ApplicationResources" />  
  37.        
  38.     <!---->  
  39.     <plug-in  
  40.         className="org.springframework.web.struts.ContextLoaderPlugIn">  
  41.         <set-property property="contextConfigLocation"  
  42.             value="/WEB-INF/applicationContext.xml" />  
  43.     plug-in>  
  44. struts-config>  
  45.   

 Spring配置代码

xml 代码
  1. <!---->xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">  
  5.        
  6.     <!---->    
  7.     <!---->  
  8.        
  9.     <bean id="dataSourceTrade"  
  10.         class="org.apache.commons.dbcp.BasicDataSource">  
  11.         <property name="driverClassName"  
  12.             value="com.microsoft.jdbc.sqlserver.SQLServerDriver">  
  13.         property>  
  14.         <property name="url"  
  15.             value="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Trade">  
  16.         property>  
  17.         <property name="username" value="share">property>  
  18.         <property name="password" value="sa">property>  
  19.     bean>  
  20.   
  21.     <bean id="sessionFactoryTrade"  
  22.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  23.         <property name="dataSource">  
  24.             <ref bean="dataSourceTrade" />  
  25.         property>  
  26.         <property name="hibernateProperties">  
  27.             <props>  
  28.                 <prop key="hibernate.dialect">  
  29.                     org.hibernate.dialect.SQLServerDialect   
  30.                 prop>  
  31.                 <prop key="hibernate.show_sql">trueprop>  
  32.                 <prop key="current_session_context_class">threadprop>  
  33.                 <prop key="connection.pool_size">10prop>  
  34.                 <prop key="hibernate.hbm2ddl.auto">updateprop>  
  35.             props>  
  36.         property>  
  37.         <property name="mappingResources">  
  38.             <list>list>  
  39.         property>  
  40.     bean>  
  41.        
  42.     <!---->  
  43.        
  44.     <bean id="dataSourceRush"  
  45.         class="org.apache.commons.dbcp.BasicDataSource">  
  46.         <property name="driverClassName"  
  47.             value="com.microsoft.jdbc.sqlserver.SQLServerDriver">  
  48.         property>  
  49.         <property name="url"  
  50.             value="jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Rush">  
  51.         property>  
  52.         <property name="username" value="share">property>  
  53.         <property name="password" value="sa">property>  
  54.     bean>  
  55.   
  56.     <bean id="sessionFactoryRush"  
  57.         class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  58.         <property name="dataSource">  
  59.             <ref bean="dataSourceTrade" />  
  60.         property>  
  61.         <property name="hibernateProperties">  
  62.             <props>  
  63.                 <prop key="hibernate.dialect">  
  64.                     org.hibernate.dialect.SQLServerDialect   
  65.                 prop>  
  66.             props>  
  67.         property>  
  68.         <property name="mappingResources">  
  69.             <list>  
  70.                 <value>com/trade/vo/rush/Drug.hbm.xmlvalue>  
  71.             list>  
  72.         property>  
  73.     bean>          
  74.     <!---->  
  75.     <bean id="DrugDAOHibernate" class="com.trade.dao.hibernate.DrugDAOHibernate">  
  76.         <property name="sessionFactory">  
  77.             <ref bean="sessionFactoryRush" />  
  78.         property>  
  79.     bean>  
  80.     <bean id="DrugService" class="com.trade.service.DrugService">  
  81.         <property name="ddh">  
  82.             <ref bean="DrugDAOHibernate" />  
  83.         property>  
  84.     bean>  
  85.        
  86.     <bean name="/drugQuery" abstract="false" lazy-init="default"  
  87.         autowire="default" dependency-check="default" class="com.trade.struts.action.DrugAction">  
  88.         <property name="ds">  
  89.             <ref bean="DrugService" />  
  90.         property>  
  91.     bean>beans>  

三、DAOImpl、Service 业务逻辑部分

因为主要是介绍分页,这里只放分页相关代码

DrugDAOHibernate类,这里使用的方法参考(抄袭。。)了Robbin等关于使用离线Criteria实现查询的代码

java 代码
  1. package com.trade.dao.hibernate;   
  2.   
  3. import java.util.List;   
  4.   
  5. import org.apache.commons.logging.Log;   
  6. import org.apache.commons.logging.LogFactory;   
  7. import org.hibernate.Criteria;   
  8. import org.hibernate.HibernateException;   
  9. import org.hibernate.Session;   
  10. import org.hibernate.criterion.DetachedCriteria;   
  11. import org.hibernate.criterion.Projections;   
  12. import org.springframework.orm.hibernate3.HibernateCallback;   
  13. import org.springframework.orm.hibernate3.support.HibernateDaoSupport;   
  14.   
  15. import com.trade.dao.IDrugDAO;   
  16. import com.trade.vo.DrugDAO;   
  17. import com.trade.vo.rush.Drug;   
  18.   
  19. public class DrugDAOHibernate extends HibernateDaoSupport implements IDrugDAO {   
  20.   
  21.     private static final Log log = LogFactory.getLog(DrugDAO.class);   
  22.        
  23.         //获得 符合查询条件的记录数目   
  24.     public Long getDrugCount(final DetachedCriteria detachedCriteria) {        
  25.         return  (Long)getHibernateTemplate().execute(new HibernateCallback() {    
  26.             public Object doInHibernate(Session session) throws HibernateException {    
  27.                 Criteria criteria = detachedCriteria.getExecutableCriteria(session);   
  28.                 Long count= Long.parseLong((criteria.setProjection(Projections.rowCount()).uniqueResult()).toString());   
  29.                 criteria.setProjection(null);    
  30.                 return count;   
  31.                 }    
  32.         }, true);          
  33.     }   
  34.   
  35.     //根据条件进行查询、分页   
  36.     public List listByConditions(final DetachedCriteria detachedCriteria,final int pageNo,final int pageSize) {   
  37.            
  38.         return (List) getHibernateTemplate().execute(new HibernateCallback() {    
  39.             public Object doInHibernate(Session session) throws HibernateException {    
  40.                 Criteria criteria = detachedCriteria.getExecutableCriteria(session);   
  41.                 criteria.setMaxResults(pageSize);   
  42.                 criteria.setFirstResult((pageNo-1)*pageSize);   
  43.                 return criteria.list();    
  44.             }    
  45.         }, true);    
  46.     }   
  47.   
  48.     }   

Service层很简单

java 代码
  1. package com.trade.service;   
  2.   
  3. import java.util.List;   
  4.   
  5. import org.hibernate.criterion.DetachedCriteria;   
  6.   
  7. import com.trade.dao.hibernate.DrugDAOHibernate;   
  8.   
  9.   
  10.   
  11. public class DrugService {   
  12. //由Spring注入DrugDAOHibernate实例   
  13. private DrugDAOHibernate ddh ;   
  14.   
  15. public DrugDAOHibernate getDdh() {   
  16.     return ddh;   
  17. }   
  18.   
  19. public void setDdh(DrugDAOHibernate ddh) {   
  20.     this.ddh = ddh;   
  21. }   
  22.   
  23. //获得满足条件的记录数   
  24. public List listByConditions(final DetachedCriteria detachedCriteria,final int pageNo,final int pageSize){   
  25.     return ddh.listByConditions(detachedCriteria,pageNo,pageSize);   
  26.        
  27. }   
  28. //根据条件进行查询、分页   
  29. public Long getDrugCount(final DetachedCriteria detachedCriteria){     
  30.     return ddh.getDrugCount(detachedCriteria);   
  31. }   
  32. }  
字数有限制。。请见下文。。
分享到:
评论
4 楼 amcucn 2008-10-19  
不错,和我目前所用到的方法基本上是如出一辙!
3 楼 javaxy 2008-10-19  
下文呢?
2 楼 erlyhds 2008-10-18  
<div class='quote_title'>brimstone 写道</div>
<div class='quote_div'><span style='font-family: Arial;'>
<p>2个月前,因为项目需要开始接触到SSH ,以前只用过JSP 开发过项目,所以对于SSH 一切都是新鲜玩意,虽然学习的过程是痛苦的,但是解决问题的快乐只有自己能体会到。<br/>在这里是我第一次写Blog,一是为了能够和这里的朋友共同进步,二是为了记录自己收获的点点滴滴,三是为了能够给和我一样的初学者分享所得——严重跑题。。 </p>
<p><span style='font-family: Arial;'>言归正传,下面是我的实现方法</span></p>
<span style='font-family: Arial;'>
<p><br/>一、开发环境<br/>JDK1.5 Hibernate 3.1 Struts 1.2 Spring2.0 MyEclplise 5.5GA</p>
<p>二、Struts 和 Spring配置<br/> Struts配置文件</p>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'><ol class='dp-xml'>
<li class='alt'><span><span class='tag'><!----><span class='tag-name'>xml</span><span> </span><span class='attribute'>version</span><span>=</span><span class='attribute-value'>"1.0"</span><span> </span><span class='attribute'>encoding</span><span>=</span><span class='attribute-value'>"UTF-8"</span><span class='tag'>?&gt;</span><span>  </span></span> </span></li>
<li><span><!----><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>  </span> </li>
<li><span class='tag'>&lt;</span><span class='tag-name'>struts-config</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>data-sources</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>form-beans</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>form-bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"drugForm"</span><span> </span><span class='attribute'>type</span><span>=</span><span class='attribute-value'>"com.trade.struts.form.DrugForm"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>form-bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"drugQueryForm"</span><span> </span><span class='attribute'>type</span><span>=</span><span class='attribute-value'>"com.trade.struts.queryform.DrugQueryForm"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>form-bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"baseForm"</span><span> </span><span class='attribute'>type</span><span>=</span><span class='attribute-value'>"com.trade.struts.queryform.BaseForm"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>    </span><span class='tag'><span class='tag-name'>form-beans</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>global-exceptions</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>global-forwards</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>action-mappings</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>action</span><span>  </span> </li>
<li><span>      </span><span class='attribute'>attribute</span><span>=</span><span class='attribute-value'>"drugQueryForm"</span><span>  </span> </li>
<li class='alt'><span>      </span><span class='attribute'>input</span><span>=</span><span class='attribute-value'>"/Drug/drug_list.jsp"</span><span>  </span> </li>
<li><span>      </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"drugQueryForm"</span><span>  </span> </li>
<li class='alt'><span>      </span><span class='attribute'>parameter</span><span>=</span><span class='attribute-value'>"method"</span><span>  </span> </li>
<li><span>      </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/drugQuery"</span><span>  </span> </li>
<li class='alt'><span>      </span><span class='attribute'>scope</span><span>=</span><span class='attribute-value'>"request"</span><span>  </span> </li>
<li><span>      </span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>      </span><span class='tag'>&lt;</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"success"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/index.jsp"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>      </span><span class='tag'>&lt;</span><span class='tag-name'>forward</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"list"</span><span> </span><span class='attribute'>path</span><span>=</span><span class='attribute-value'>"/Drug/drug_list.jsp"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>action</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>               </span> </li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>action-mappings</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>       </span> </li>
<li class='alt'><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>controller</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>set-property</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"processorClass"</span><span>  </span> </li>
<li><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"org.springframework.web.struts.DelegatingRequestProcessor"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>controller</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>       </span> </li>
<li class='alt'><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>message-resources</span><span> </span><span class='attribute'>parameter</span><span>=</span><span class='attribute-value'>"com.trade.struts.ApplicationResources"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>       </span> </li>
<li><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>plug-in</span><span>  </span> </li>
<li><span>        </span><span class='attribute'>className</span><span>=</span><span class='attribute-value'>"org.springframework.web.struts.ContextLoaderPlugIn"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>set-property</span><span> </span><span class='attribute'>property</span><span>=</span><span class='attribute-value'>"contextConfigLocation"</span><span>  </span> </li>
<li><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"/WEB-INF/applicationContext.xml"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>plug-in</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span class='tag'><span class='tag-name'>struts-config</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>  </span> </li>
</ol></div>
<p> Spring配置代码</p>
<div class='code_title'>xml 代码</div>
<div class='dp-highlighter'><ol class='dp-xml'>
<li class='alt'><span><span class='tag'><!----><span class='tag-name'>xml</span><span> </span><span class='attribute'>version</span><span>=</span><span class='attribute-value'>"1.0"</span><span> </span><span class='attribute'>encoding</span><span>=</span><span class='attribute-value'>"UTF-8"</span><span class='tag'>?&gt;</span><span>  </span></span> </span></li>
<li><span class='tag'>&lt;</span><span class='tag-name'>beans</span><span> </span><span class='attribute'>xmlns</span><span>=</span><span class='attribute-value'>"http://www.springframework.org/schema/beans"</span><span>  </span> </li>
<li class='alt'><span>    </span><span class='attribute'>xmlns:xsi</span><span>=</span><span class='attribute-value'>"http://www.w3.org/2001/XMLSchema-instance"</span><span>  </span> </li>
<li><span>    </span><span class='attribute'>xsi:schemaLocation</span><span>=</span><span class='attribute-value'>"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>       </span> </li>
<li><span>    </span><span class='comments'><!----></span><span>    </span> </li>
<li class='alt'><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li><span>       </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"dataSourceTrade"</span><span>  </span> </li>
<li><span>        </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"org.apache.commons.dbcp.BasicDataSource"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"driverClassName"</span><span>  </span> </li>
<li><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"com.microsoft.jdbc.sqlserver.SQLServerDriver"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"url"</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Trade"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"username"</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"share"</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"password"</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"sa"</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>  </span> </li>
<li class='alt'><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"sessionFactoryTrade"</span><span>  </span> </li>
<li><span>        </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"dataSource"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>ref</span><span> </span><span class='attribute'>bean</span><span>=</span><span class='attribute-value'>"dataSourceTrade"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"hibernateProperties"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>props</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"hibernate.dialect"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>                    org.hibernate.dialect.SQLServerDialect   </span> </li>
<li><span>                </span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"hibernate.show_sql"</span><span class='tag'>&gt;</span><span>true</span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"current_session_context_class"</span><span class='tag'>&gt;</span><span>thread</span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"connection.pool_size"</span><span class='tag'>&gt;</span><span>10</span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"hibernate.hbm2ddl.auto"</span><span class='tag'>&gt;</span><span>update</span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>            </span><span class='tag'><span class='tag-name'>props</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"mappingResources"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>list</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>list</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>       </span> </li>
<li><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li class='alt'><span>       </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"dataSourceRush"</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"org.apache.commons.dbcp.BasicDataSource"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"driverClassName"</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"com.microsoft.jdbc.sqlserver.SQLServerDriver"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"url"</span><span>  </span> </li>
<li><span>            </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"jdbc:microsoft:sqlserver://localhost:1433;DataBaseName=Rush"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"username"</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"share"</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"password"</span><span> </span><span class='attribute'>value</span><span>=</span><span class='attribute-value'>"sa"</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"sessionFactoryRush"</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"org.springframework.orm.hibernate3.LocalSessionFactoryBean"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"dataSource"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>ref</span><span> </span><span class='attribute'>bean</span><span>=</span><span class='attribute-value'>"dataSourceTrade"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"hibernateProperties"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>props</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>prop</span><span> </span><span class='attribute'>key</span><span>=</span><span class='attribute-value'>"hibernate.dialect"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>                    org.hibernate.dialect.SQLServerDialect   </span> </li>
<li class='alt'><span>                </span><span class='tag'><span class='tag-name'>prop</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>            </span><span class='tag'><span class='tag-name'>props</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"mappingResources"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>list</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>                </span><span class='tag'>&lt;</span><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>com/trade/vo/rush/Drug.hbm.xml</span><span class='tag'><span class='tag-name'>value</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>            </span><span class='tag'><span class='tag-name'>list</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span><span>       </span> </li>
<li class='alt'><span>    </span><span class='comments'><!----></span><span>  </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"DrugDAOHibernate"</span><span> </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"com.trade.dao.hibernate.DrugDAOHibernate"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"sessionFactory"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>ref</span><span> </span><span class='attribute'>bean</span><span>=</span><span class='attribute-value'>"sessionFactoryRush"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>id</span><span>=</span><span class='attribute-value'>"DrugService"</span><span> </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"com.trade.service.DrugService"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"ddh"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>ref</span><span> </span><span class='attribute'>bean</span><span>=</span><span class='attribute-value'>"DrugDAOHibernate"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>       </span> </li>
<li><span>    </span><span class='tag'>&lt;</span><span class='tag-name'>bean</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"/drugQuery"</span><span> </span><span class='attribute'>abstract</span><span>=</span><span class='attribute-value'>"false"</span><span> </span><span class='attribute'>lazy-init</span><span>=</span><span class='attribute-value'>"default"</span><span>  </span> </li>
<li class='alt'><span>        </span><span class='attribute'>autowire</span><span>=</span><span class='attribute-value'>"default"</span><span> </span><span class='attribute'>dependency-check</span><span>=</span><span class='attribute-value'>"default"</span><span> </span><span class='attribute'>class</span><span>=</span><span class='attribute-value'>"com.trade.struts.action.DrugAction"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'>&lt;</span><span class='tag-name'>property</span><span> </span><span class='attribute'>name</span><span>=</span><span class='attribute-value'>"ds"</span><span class='tag'>&gt;</span><span>  </span> </li>
<li class='alt'><span>            </span><span class='tag'>&lt;</span><span class='tag-name'>ref</span><span> </span><span class='attribute'>bean</span><span>=</span><span class='attribute-value'>"DrugService"</span><span> </span><span class='tag'>/&gt;</span><span>  </span> </li>
<li><span>        </span><span class='tag'><span class='tag-name'>property</span><span class='tag'>&gt;</span><span>  </span> </span></li>
<li class='alt'><span>    </span><span class='tag'><span class='tag-name'>bean</span><span class='tag'>&gt;</span><span class='tag'><span class='tag-name'>beans</span><span class='tag'>&gt;</span><span>  </span> </span></span></li>
</ol></div>
<p>三、DAOImpl、Service 业务逻辑部分</p>
<p>因为主要是介绍分页,这里只放分页相关代码</p>
<p>DrugDAOHibernate类,这里使用的方法参考(抄袭。。)了Robbin等关于使用离线Criteria实现查询的代码</p>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'><ol class='dp-j'>
<li class='alt'><span><span class='keyword'>package</span><span> com.trade.dao.hibernate;   </span></span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> java.util.List;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.apache.commons.logging.Log;   </span> </li>
<li><span class='keyword'>import</span><span> org.apache.commons.logging.LogFactory;   </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.hibernate.Criteria;   </span> </li>
<li><span class='keyword'>import</span><span> org.hibernate.HibernateException;   </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.hibernate.Session;   </span> </li>
<li><span class='keyword'>import</span><span> org.hibernate.criterion.DetachedCriteria;   </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.hibernate.criterion.Projections;   </span> </li>
<li><span class='keyword'>import</span><span> org.springframework.orm.hibernate3.HibernateCallback;   </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.springframework.orm.hibernate3.support.HibernateDaoSupport;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> com.trade.dao.IDrugDAO;   </span> </li>
<li><span class='keyword'>import</span><span> com.trade.vo.DrugDAO;   </span> </li>
<li class='alt'><span class='keyword'>import</span><span> com.trade.vo.rush.Drug;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> DrugDAOHibernate </span><span class='keyword'>extends</span><span> HibernateDaoSupport </span><span class='keyword'>implements</span><span> IDrugDAO {   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span>    </span><span class='keyword'>private</span><span> </span><span class='keyword'>static</span><span> </span><span class='keyword'>final</span><span> Log log = LogFactory.getLog(DrugDAO.</span><span class='keyword'>class</span><span>);   </span> </li>
<li><span>       </span> </li>
<li class='alt'><span>        </span><span class='comment'>//获得 符合查询条件的记录数目 </span><span>  </span> </li>
<li><span>    </span><span class='keyword'>public</span><span> Long getDrugCount(</span><span class='keyword'>final</span><span> DetachedCriteria detachedCriteria) {        </span> </li>
<li class='alt'><span>        </span><span class='keyword'>return</span><span>  (Long)getHibernateTemplate().execute(</span><span class='keyword'>new</span><span> HibernateCallback() {    </span> </li>
<li><span>            </span><span class='keyword'>public</span><span> Object doInHibernate(Session session) </span><span class='keyword'>throws</span><span> HibernateException {    </span> </li>
<li class='alt'><span>                Criteria criteria = detachedCriteria.getExecutableCriteria(session);   </span> </li>
<li><span>                Long count= Long.parseLong((criteria.setProjection(Projections.rowCount()).uniqueResult()).toString());   </span> </li>
<li class='alt'><span>                criteria.setProjection(</span><span class='keyword'>null</span><span>);    </span> </li>
<li><span>                </span><span class='keyword'>return</span><span> count;   </span> </li>
<li class='alt'><span>                }    </span> </li>
<li><span>        }, </span><span class='keyword'>true</span><span>);          </span> </li>
<li class='alt'><span>    }   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span>    </span><span class='comment'>//根据条件进行查询、分页 </span><span>  </span> </li>
<li><span>    </span><span class='keyword'>public</span><span> List listByConditions(</span><span class='keyword'>final</span><span> DetachedCriteria detachedCriteria,</span><span class='keyword'>final</span><span> </span><span class='keyword'>int</span><span> pageNo,</span><span class='keyword'>final</span><span> </span><span class='keyword'>int</span><span> pageSize) {   </span> </li>
<li class='alt'><span>           </span> </li>
<li><span>        </span><span class='keyword'>return</span><span> (List) getHibernateTemplate().execute(</span><span class='keyword'>new</span><span> HibernateCallback() {    </span> </li>
<li class='alt'><span>            </span><span class='keyword'>public</span><span> Object doInHibernate(Session session) </span><span class='keyword'>throws</span><span> HibernateException {    </span> </li>
<li><span>                Criteria criteria = detachedCriteria.getExecutableCriteria(session);   </span> </li>
<li class='alt'><span>                criteria.setMaxResults(pageSize);   </span> </li>
<li><span>                criteria.setFirstResult((pageNo-</span><span class='number'>1</span><span>)*pageSize);   </span> </li>
<li class='alt'><span>                </span><span class='keyword'>return</span><span> criteria.list();    </span> </li>
<li><span>            }    </span> </li>
<li class='alt'><span>        }, </span><span class='keyword'>true</span><span>);    </span> </li>
<li><span>    }   </span> </li>
<li class='alt'><span>  </span> </li>
<li><span>    }   </span> </li>
</ol></div>
<p>Service层很简单</p>
<div class='code_title'>java 代码</div>
<div class='dp-highlighter'><ol class='dp-j'>
<li class='alt'><span><span class='keyword'>package</span><span> com.trade.service;   </span></span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> java.util.List;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> org.hibernate.criterion.DetachedCriteria;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>import</span><span> com.trade.dao.hibernate.DrugDAOHibernate;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span>  </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>public</span><span> </span><span class='keyword'>class</span><span> DrugService {   </span> </li>
<li><span class='comment'>//由Spring注入DrugDAOHibernate实例 </span><span>  </span> </li>
<li class='alt'><span class='keyword'>private</span><span> DrugDAOHibernate ddh ;   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>public</span><span> DrugDAOHibernate getDdh() {   </span> </li>
<li><span>    </span><span class='keyword'>return</span><span> ddh;   </span> </li>
<li class='alt'><span>}   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='keyword'>public</span><span> </span><span class='keyword'>void</span><span> setDdh(DrugDAOHibernate ddh) {   </span> </li>
<li><span>    </span><span class='keyword'>this</span><span>.ddh = ddh;   </span> </li>
<li class='alt'><span>}   </span> </li>
<li><span>  </span> </li>
<li class='alt'><span class='comment'>//获得满足条件的记录数 </span><span>  </span> </li>
<li><span class='keyword'>public</span><span> List listByConditions(</span><span class='keyword'>final</span><span> DetachedCriteria detachedCriteria,</span><span class='keyword'>final</span><span> </span><span class='keyword'>int</span><span> pageNo,</span><span class='keyword'>final</span><span> </span><span class='keyword'>int</span><span> pageSize){   </span> </li>
<li class='alt'><span>    </span><span class='keyword'>return</span><span> ddh.listByConditions(detachedCriteria,pageNo,pageSize);   </span> </li>
<li><span>       </span> </li>
<li class='alt'><span>}   </span> </li>
<li><span class='comment'>//根据条件进行查询、分页 </span><span>  </span> </li>
<li class='alt'><span class='keyword'>public</span><span> Long getDrugCount(</span><span class='keyword'>final</span><span> DetachedCriteria detachedCriteria){     </span> </li>
<li><span>    </span><span class='keyword'>return</span><span> ddh.getDrugCount(detachedCriteria);   </span> </li>
<li class='alt'><span>}   </span> </li>
<li><span>}  </span> </li>
</ol></div>
</span></span>字数有限制。。请见下文。。</div>
<p> </p>
1 楼 bobomtv17 2007-12-13  
很不错的例子,我也在学习SSH,谢谢了!

相关推荐

    STRUTS2+HIBERNATE详细的分页实现代码详细的分页实现代码

    根据提供的标题、描述、标签及部分内容,我们可以了解到这篇文章主要探讨的是如何在Struts2与Hibernate框架结合下实现分页功能。接下来将详细解析Struts2与Hibernate如何协作完成这一任务。 ### Struts2与Hibernate...

    struts hibernate spring 分页ssh分页

    2. **在DAO层实现分页查询**:使用Hibernate的Criteria、HQL或者SQL配合分页参数(如页码和每页大小)来执行分页查询。 3. **在Service层处理分页逻辑**:Service层根据业务需求,调用DAO层的分页查询方法,并返回...

    hibernate,struts,spring,JSP,实现分页技术

    JAVA分页大全.doc Hibernate分页查询.doc hibernate实现分页技术.txt struts实现分页技术源代码txt Struts+hibernate制作...spring+struts+hibernate 分页问题.txt spring+hibernate分页技术.txt jsp实现分页技术.txt

    struts+hibernate+spring集成实现分页

    SSH(Struts、Spring、Hibernate)集成是Java Web开发中的常见模式,用于创建复杂的业务逻辑和数据管理。在本资料中,我们将深入探讨如何利用这三大框架实现分页功能。 首先,Struts作为MVC(模型-视图-控制器)...

    ssh struts hibernate spring 分页

    SSH(Struts、Hibernate、Spring)是Java Web开发中一种常见的技术栈,它结合了MVC框架Struts、对象关系映射工具Hibernate和依赖注入框架Spring。这些组件协同工作,为开发者提供了一种高效、灵活的开发环境。下面将...

    开发基于Struts Spring Hibernate Ajax的网上信息发布平台(Struts Hibernate Spring Ajax)--Chapter1

    在本章中,我们将深入探讨如何开发一个基于Struts、Spring、Hibernate和Ajax的网上信息发布平台。这四个技术是Java Web开发中的核心组件,它们各自承担着不同的职责,共同构建了一个强大而灵活的后端架构。 **...

    struts spring hibernate 登陆 SSH整合分页功能

    struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页

    Struts2 hibernate spring分页实例

    在这个“Struts2 Hibernate Spring分页实例”中,开发者将展示如何在这些框架的集成环境中实现数据的分页显示。分页是Web应用中常见的一种功能,它能够帮助用户更好地浏览和管理大量的数据,避免一次性加载过多内容...

    spring+struts2+hibernate整合实现分页

    在这个项目中,“spring+struts2+hibernate整合实现分页”是一个基础教程,旨在帮助初学者理解如何在SSH框架下实现数据的分页展示。下面将详细讲解这个主题中的关键知识点。 1. **Spring框架**:Spring是Java应用的...

    struts2+spring2+hibernate3注册查询搜索分页实例

    搜索功能通常涉及到条件查询,可以利用Hibernate3的Criteria API或者HQL动态构造查询语句,根据用户输入的关键词匹配数据库中的记录。搜索结果同样可以结合分页进行展示。 总的来说,这个"Struts2+Spring2+...

    Hibernate+Struts+Spring 实现的通用分页查询

    总结来说,使用Hibernate、Struts和Spring实现的通用分页查询,涉及了Java Web开发中的多个层次,包括模型、持久层接口、持久层实现、业务层和服务层的交互,以及视图层的渲染。这种分页机制灵活且可复用,可以适应...

    spring+struts+hibernate实现分页

    总的来说,通过Spring、Struts和Hibernate的集成,我们可以构建出一个强大的Web应用框架,其中分页功能的实现主要依赖于Spring管理的SessionFactory、Struts的Action和Spring的IoC容器,以及自定义的PageUtil和Page...

    Struts2 hibernate spring分页配套lib(2)

    Struts2 hibernate spring分页配套lib(2) 上传的可真慢啊 Struts2 hibernate spring分页配套lib(3)我始终上传不上去 不知道怎么弄的 例子运行http://localhost:8080/page/emp/list.action

    Struts+Hibernate+Spring的分页

    总结来说,这个项目展示了如何在Struts、Hibernate和Spring三大框架下实现分页功能,涵盖了前端请求处理、后端分页逻辑以及数据查询的各个方面。无论是SQL还是HQL,都能有效地应用于分页场景,开发者可以根据项目...

    struts hibernate spring 分页 ssh 控件 实验室 管理 系统

    在SSH框架下,可以通过Struts的拦截器或Spring的Pageable接口来实现分页查询,从而避免一次性加载大量数据导致的性能问题。 DWR(Direct Web Remoting)是一种JavaScript到Java的远程调用技术,它使得前端能够直接...

    Struts2 hibernate spring分页配套lib(1)

    Struts2 hibernate spring分页配套lib 共三个分卷 这是一

    Struts2 hibernate spring分页配套lib(3)

    Struts2 hibernate spring分页配套lib(3) 上次怎么没成功啊

    使用Struts + Spring + Hibernate完成分页笔记

    在分页实现中,Spring可以管理Struts的Action类以及Hibernate的数据访问对象(DAO)。通过Spring的IOC(Inversion of Control,控制反转),我们可以将DAO的实例注入到Action中,使得Action无需关心DAO的具体创建...

    Struts+Hibernate+Spring整合分页实例(带排序功能)part1

    这是Java常用框架阶段在为学生答疑时做的一个SSH整合分页实例(第一部分),涉及了SSH整合、日期模糊查询、查询条件绑定、查询结果排序等功能,希望能为大家提供一些思路。 分页是绝大多数MIS系统必需的功能之一,...

    ext3+struts2+hibernate+spring的CRUD+分页

    "ext3+struts2+hibernate+spring的CRUD+分页"是一个典型的Java Web开发组合,用于实现全面的数据管理功能。这个组合充分利用了各个框架的优势,提供了一个强大的后端数据处理和前端展示的解决方案。 首先,EXT3是一...

Global site tag (gtag.js) - Google Analytics