spring与ibatis结合

本文介绍了一种基于IBatis框架的数据库操作配置方法,通过详细展示sql-map-config.xml配置文件内容,结合Spring框架进行整合,并提供了具体的DAO实现案例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1: sql-map-config.xml  中配置

 

<sqlMapConfig>
 <properties resource="db-dialect.properties" />
 <settings cacheModelsEnabled="true" enhancementEnabled="true"
  lazyLoadingEnabled="false" errorTracingEnabled="true" maxRequests="32"
  maxSessions="10" maxTransactions="5" useStatementNamespaces="true" />
    <sqlMap resource="com/nstc/sql/${dialect}/HRInterface.xml" />
   
</sqlMapConfig>

 

(说明:db-dialect.properties 为编译后在classes目录下的文件,文件内容:dialect=oracle,目的:可配置性)

 

2:基类   BaseDao

 

public class BaseDao extends SqlMapClientDaoSupport{

   
}

 

3:applicationContext.xml中如下配置

 

 <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="location">
      <value>/WEB-INF/applicationContext.properties</value>
    </property>
    <property name="fileEncoding">
      <value>GBK</value>
    </property>
  </bean>

 


  <bean id="dataSource.FBCM"
        class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName">
      <value>${jndi.oradata}</value>
    </property>
  </bean>

 

<bean id="sqlMapClient"
        class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
    <property name="configLocation">
      <value>/WEB-INF/sql-map-config.xml</value>
    </property>
     <property name="dataSource">
      <ref bean="dataSource.FBCM" />
    </property> 
  </bean>

 


  <bean id="baseDao"
        class="com.nstc.fbth.dao.BaseDao">
    <property name="sqlMapClient">
      <ref local="sqlMapClient" />
    </property>

 

<bean  id="hrDao"  class="com.nstc.HRInterface.dao.HRInterfaceDao" parent="baseDao"></bean〉

 

 

4:在hrdao中使用

 

public class HRInterfaceDao extends BaseDao {

 

 public  String  getHRMessage(String vcEmployeeID){
  
  Integer   count = (Integer)this.getSqlMapClientTemplate().queryForObject

 

  ("HRInter.getHRMessage",vcEmployeeID);
    
     return  count+"";
 }

 

 public  void   updateHRMessage(EmpMessageInfo  empMessageInfo){
  
  this.getSqlMapClientTemplate().update("HRInter.updateHRMessage",empMessageInfo);


 }

 

 public  void   insertHRMessage(EmpMessageInfo  empMessageInfo){
  
  this.getSqlMapClientTemplate().insert("HRInter.insertHRMessage",empMessageInfo);
  
 }

 

 

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值