问题

/**
  * 分布查询
  * @param pageNum 当前页码
  * @param pageCount 每页显示的条数
  * @param hql 要执行的hql查询语句
  */
 public List listByPage(int pageNum, int pageCount, String hql) {
  Session session = null;
  List list = null;
  try{
  session = super.getSession();
  session.clear();
  Query query = session.createQuery(hql);
  //query.setCacheable(false);
  int firstResultIndex = pageCount * (pageNum - 1);
  query.setFirstResult(firstResultIndex);
  query.setMaxResults(pageCount);
  list = query.list();
  }catch(Exception e){
   e.printStackTrace();
  }finally{
   //session.flush();
   session.clear();
   session.disconnect();
   HibernateSessionFactory.closeSession();
   session = null;
  }
  return list;
 }

 

 

/**
  * 查询出商家推荐前几条数据
  * @param pageNum 页码
  * @param pageCount 显示的条数
  */
 public List getTopList(int pageNum,int pageCount) {
  String hql = "select tuijian from Ttuijian as tuijian order by tuijian.tuijiantime desc";
  List list = super.listByPage(pageNum, pageCount, hql);
  if (list != null) {
   for (int i = 0; i < list.size(); i++) {
    Hibernate.initialize(((Ttuijian)list.get(i)).getTbusiness());
   }
  }
  return list;
 }

 

 

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
 http://www.springframework.org/schema/tx
 http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
 http://www.springframework.org/schema/aop
 http://www.springframework.org/schema/aop/spring-aop-2.0.xsd"
 default-lazy-init="true">

<bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation">
   <value>classpath:hibernate.cfg.xml</value>
  </property>
 </bean>
<!--
 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource">
  <property name="driverClassName"
   value="com.mysql.jdbc.Driver">
  </property>
  <property name="url"
   value="jdbc:mysql://localhost:3306/rkdb?zeroDateTimeBehavior=convertToNull">
  </property>
  <property name="username" value="root"></property>
  <property name="password" value="123"></property>
 </bean>
 
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource">
   <ref bean="dataSource" />
  </property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">
     org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
   </props>
  </property>
  <property name="mappingResources">
   <list>
    <value>com/dreamming/entity/Tblogin.hbm.xml</value>
    <value>com/dreamming/entity/Tbusiness.hbm.xml</value>
    <value>com/dreamming/entity/Tfanwei.hbm.xml</value>
    <value>com/dreamming/entity/Tfood.hbm.xml</value>
    <value>com/dreamming/entity/Tfoodtype.hbm.xml</value>
    <value>com/dreamming/entity/Tguanggao.hbm.xml</value>
    <value>com/dreamming/entity/Thao.hbm.xml</value>
    <value>com/dreamming/entity/Tjie.hbm.xml</value>
    <value>com/dreamming/entity/Tjifen.hbm.xml</value>
    <value>com/dreamming/entity/Tlogin.hbm.xml</value>
    <value>com/dreamming/entity/Torder.hbm.xml</value>
    <value>com/dreamming/entity/Tpinglun.hbm.xml</value>
    <value>com/dreamming/entity/Tpingluntype.hbm.xml</value>
    <value>com/dreamming/entity/Tqu.hbm.xml</value>
    <value>com/dreamming/entity/Tretie.hbm.xml</value>
    <value>com/dreamming/entity/Trole.hbm.xml</value>
    <value>com/dreamming/entity/Tshangwu.hbm.xml</value>
    <value>com/dreamming/entity/Tshoucang.hbm.xml</value>
    <value>com/dreamming/entity/Ttuijian.hbm.xml</value>
    <value>com/dreamming/entity/Tuser.hbm.xml</value>
    <value>com/dreamming/entity/Txiaoqu.hbm.xml</value>
    <value>com/dreamming/entity/Tyijian.hbm.xml</value>
    <value>com/dreamming/entity/Tyouqing.hbm.xml</value>
   </list>
  </property>
 </bean>
 -->
 
 <bean id="myHibTxManager"
  class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <tx:advice id="txAdvice" transaction-manager="myHibTxManager">
  <tx:attributes>
    <!-- 对查找方法进行只读事务通知要求查找方法以find开头可按需要修改 -->
            <tx:method name="find*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="get" propagation="SUPPORTS" read-only="true" />
            <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="query*" propagation="SUPPORTS" read-only="true" />
            <!-- 对其它方法如增 删 改进行事务支持 -->
            <tx:method name="add" propagation="REQUIRED" rollback-for="Throwable" />
            <tx:method name="add*" propagation="REQUIRED" rollback-for="Throwable" />
            <tx:method name="save*" propagation="REQUIRED" />
            <tx:method name="remove" propagation="REQUIRED" />
            <tx:method name="remove*" propagation="REQUIRED" />
            <tx:method name="delete*" propagation="REQUIRED" />
            <tx:method name="move*" propagation="REQUIRED" />
            <tx:method name="update" propagation="REQUIRED" />
            <tx:method name="update*" propagation="REQUIRED" />
            <tx:method name="is*" propagation="REQUIRED" />
            <tx:method name="has*" propagation="REQUIRED" />
  </tx:attributes>
 </tx:advice>
 <aop:config>
  <!--
   只对GoodsBiz添加事务支持,因为前面配置的transactionManager
   是专对Hibernate的事务管理器 。
  -->
  <aop:pointcut id="serviceMethods"
   expression="execution(* com.dreamming.service.*.*(..))" />
  <!-- 织入 -->
  <aop:advisor advice-ref="txAdvice"
   pointcut-ref="serviceMethods" />
 </aop:config>
 
 <!-- 1. DAO -->
 <bean id="commonDAO"
  class="org.jb.common.dao.hibimpl.CommonDAOHibImpl">
  <property name="sessionFactory">
   <ref local="sessionFactory" />
  </property>
 </bean>


 <!-- Dao 开始 -->
 <bean id="commDao" class="com.dreamming.common.dao.hibimpl.CommonDAOHibImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <!-- 热贴 dao -->
 <bean id="retieDao" class="com.dreamming.dao.impl.RetieDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 评论 dao -->
 <bean id="pinglunDao" class="com.dreamming.dao.impl.PinglunDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 推荐 dao -->
 <bean id="tuijianDao" class="com.dreamming.dao.impl.TuijianDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 广告 dao -->
 <bean id="guanggaoDao" class="com.dreamming.dao.impl.GuanggaoDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 区 dao -->
 <bean id="quDao" class="com.dreamming.dao.impl.QuDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 街 dao -->
 <bean id="jieDao" class="com.dreamming.dao.impl.JieDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 号 dao -->
 <bean id="haoDao" class="com.dreamming.dao.impl.HaoDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 用户 dao -->
 <bean id="userDao" class="com.dreamming.dao.impl.UserDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 商家 dao -->
 <bean id="businessDao" class="com.dreamming.dao.impl.BusinessDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 
 <bean id="service" class="com.dreamming.service.impl.Service">
  <property name="commonDAO" ref="commDao"></property>
 </bean>
 <!-- 热贴 Service -->
 <bean id="retieService" class="com.dreamming.service.impl.RetieServiceImpl" parent="service">
  
 </bean>
 <!-- 评论 Service -->
 <bean id="pinglunService" class="com.dreamming.service.impl.PinglunServiceImpl" parent="service">
  
 </bean>
 <!-- 推荐 Service -->
 <bean id="tuijianService" class="com.dreamming.service.impl.TuijianServiceImpl" parent="service">
  
 </bean>
 <!-- 广告 Service -->
 <bean id="guanggaoService" class="com.dreamming.service.impl.GuanggaoServiceImpl" parent="service">
  
 </bean>
 <!-- 区 Service -->
 <bean id="quService" class="com.dreamming.service.impl.QuServiceImpl" parent="service">
  
 </bean>
 <!-- 街 Service -->
 <bean id="jieService" class="com.dreamming.service.impl.JieServiceImpl" parent="service">
  
 </bean>
 <!-- 号 Service -->
 <bean id="haoService" class="com.dreamming.service.impl.HaoServiceImpl" parent="service">
  
 </bean>
 <!-- 用户 Service -->
 <bean id="userService" class="com.dreamming.service.impl.UserServiceImpl" parent="service"></bean>
 <!-- 商家 Service -->
 <bean id="businessService" class="com.dreamming.service.impl.BusinessServiceImpl" parent="service"></bean>
 
 <!-- dwr dwr dwr dwr dwr dwr dwr dwr dwr dwr dwr -->
 <!-- 街道 dwr dao -->
 <bean id="dwrJieDao" class="com.dreamming.dwr.dao.impl.DwrJieDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <!-- 街道 dwr service -->
 <bean id="dwrJieService" class="com.dreamming.dwr.service.impl.DwrJieServiceImpl" parent="service">
 </bean>
 
 <!-- 号 -->
 <bean id="dwrHaoDao" class="com.dreamming.dwr.dao.impl.DwrHaoDaoImpl">
  <property name="sessionFactory" ref="sessionFactory"></property>
 </bean>
 <bean id="dwrHaoService" class="com.dreamming.dwr.service.impl.DwrHaoServiceImpl" parent="service">
 </bean>
 
 <!-- dwr dwr dwr dwr dwr dwr dwr dwr dwr dwr dwr -->
 
 <!-- 首页 Action -->
 <bean name="/index" class="com.dreamming.web.struts.action.IndexAction" scope="prototype">
  <property name="retieService" ref="retieService"></property>
  <property name="pinglunService" ref="pinglunService"></property>
  <property name="tuijianService" ref="tuijianService"></property>
  <property name="guanggaoService" ref="guanggaoService"></property>
  <property name="quService" ref="quService"></property>
  <property name="jieService" ref="jieService"></property>
 </bean>
 <bean name="/user" class="com.dreamming.web.struts.action.UserAction" scope="prototype">
  <property name="userService" ref="userService"></property>
  <property name="businessService" ref="businessService"></property>
 </bean>
</beans>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值