在使用ibatis访问数据库时,难免遇到数据库设计表为分表的,如历史表为年月分表,这样sql语句中表名需要根据需要设置为动态的。自从ibatis 2.0.9以后,ibatis支持动态表名,以下为动态表名实现方法:
<select id="selBanlanceChgByDate" resultMap="BanlanceChgMap" parameterClass="BanlanceChg">
<![CDATA[
select * from cz_BanlanceChg_$sSuffix$
where AGENT_ID = #sAgentId#
and CHARGE_DATE >= #iBeginDate#
and CHARGE_DATE <= #iEndDate#
order by CHARGE_TIME desc;
]]>
</select>
1、sSuffix表示表后缀标识,切记用$标识,不同于属性用#标识
2、后缀sSuffix的值通过对象BanlanceChg传入,可根据程序设计需要设置;