spring-ibatis使用

1)spring配置文件:

 <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
  <property name="configLocation" value="conf/sqlMapConfig.xml"></property>
  <property name="dataSource" ref="dataSource"></property>
 </bean>

2)在DAOImpl类中继承SqlMapClientDaoSupport类。并将sqlMapClient  Bean注册到此类中。

public class MonitorDaoImpl extends SqlMapClientDaoSupport implements
  IMonitorDao {

}

<bean id="monitorDao"
    class="com.**.dao.monitor.impl.MonitorDaoImpl" autowire="byName">
  <property name="sqlMapClient" ref="sqlMapClient"></property>
 </bean>

sqlMap举例:

  
    
< sqlMap namespace ="monitor" >

< select id ="t_TrafficZoneIfIPApp" parameterClass ="java.util.HashMap"
resultClass
="object.monitor.Traffic" >
select
t1.neId as neId,
t3.zoneName as zoneName,
t4.name as ifName,
t1.ipAddr as user,
t5.enName as appName,
t1.upBW as upBW,
t1.downBW as downBW ,
t1.downPPS as downPPS,
t1.upPPS as upPPS,
t1.rampupRate as rampupRate,
t1.session as session,
t1.insertTstamp as timestamp
from (
< isGreaterThan property ="topN" compareValue ="0" >
select * from $tableName$ limit #topN:INTEGER#
</ isGreaterThan >
< isLessEqual property ="topN" compareValue ="0" >
$tableName$
</ isLessEqual >
) t1
left join hsm_db.t_neinfo t2 on (t1.neId=t2.neId )
left join hsm_db.t_zoneinfo t3 on (t1.neId=t3.neId and t1.zoneId=t3.zoneId)
left join hsm_db.t_ifinfo t4 on (t1.neId=t4.neId and t1.ifId=t4.ifId)
left join hsm_db.t_appinfo t5 on (t1.neId=t5.neId and t1.appId=t5.appId)
< dynamic prepend ="WHERE" >
< isGreaterThan prepend ="AND" property ="neId" compareValue ="0" >
neId=#neId:INTEGER#
</ isGreaterThan >
< isNotEmpty prepend ="AND" property ="zoneName" >
zoneId=(select zoneId from hsm_db.t_zone where zonename=#zoneName# limit 1)
</ isNotEmpty >
< isNotEmpty prepend ="AND" property ="ifName" >
ifId=(select ifId from hsm_db.t_ifInfo where name=#ifName# and neId=#neId# limit 1)
</ isNotEmpty >
< isNotEmpty prepend ="AND" property ="user" >
ipAddr=#user#
</ isNotEmpty >
< isNotEmpty prepend ="AND" property ="appName" >
appId=#appName#
</ isNotEmpty >
< isNotEmpty prepend ="AND" property ="beginTime" >
insertTstamp
<![CDATA[ >= ]]> #beginTime:TIMESTAMP#
</ isNotEmpty >
< isNotEmpty prepend ="AND" property ="endTime" >
insertTstamp
<![CDATA[ <= ]]> #endTime:TIMESTAMP#
</ isNotEmpty >
</ dynamic >
< isNotEmpty property ="orderBy" >
order by #orderBy#
</ isNotEmpty >
< isGreaterThan property ="topN" compareValue ="0" >
limit #topN:INTEGER#
</ isGreaterThan >
</ select >
</ sqlMap >


你可能感兴趣的:(spring)