前言
他们都是优秀的持久层框架,MyBatis是现在最常用的持久层框架,可以动态地拼接sql语句,非常人性化,更适合逻辑复杂的sql;iBatis就是MyBatis前身,他们有很多相似的地方。
- 传入参数
iBatis:<select id="selectDeviceByWhere" parameterClass="Map" resultClass="BaseResultMap"> </select>
MyBatis:<select id="selectDeviceByWhere" parameterType="Map" resultMap="BaseResultMap"> </select>
- 接收参数
IBatis: 是使用 #参数#
MyBatis: 是使用 #{参数 } - 判断、循环语句
- 在IBatis中:
<isNotEmpty property="accountType" prepend="and">
<iterate property="accountType" prepend="" open="((" close="))" conjunction=") OR (">
<isEqual property="accountType[]" compareValue="bj">
COSTTYPE='prin'
</isEqual>
<isEqual property="accountType[]" compareValue="sy">
COSTTYPE='profit'
</isEqual>
<isEqual property="accountType[]" compareValue="fy">
COSTTYPE<>'prin' AND COSTTYPE<>'profit'
</isEqual>
</iterate>
</isNotEmpty>
- 在MyBatis中:
<if test="accountType!=null and accountType!=''">
and
<foreach collection="accountType" item="cp" open="((" close="))" separator=") OR (">
<if test="cp=='bj'.toString()">
COSTTYPE='prin'
</if>
<if test="cp=='sy'.toString()">
COSTTYPE='profit'
</if>
<if test="cp=='fy'.toString()">
COSTTYPE!='prin' AND COSTTYPE!='profit'
</if>
</foreach>
</if>
小结:
以上便是两者转换时,需要注意之处,仅供参考,如有不妥,欢迎留言指教。。。