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);
}
}