<insert id="saveOrUpdate" >
<selectKey keyProperty="count" resultType="int" order="BEFORE">
select count(*) from country where id = #{id}
</selectKey>
<if test="count > 0">
update country
set countryname = #{countryname},countrycode = #{countrycode}
where id = #{id}
</if>
<if test="count==0">
insert into country values(#{id},#{countryname},#{countrycode})
</if>
</insert>
转:http://limingnihao.iteye.com/blog/782190 if test -- 检测值是否符合条件 foreach -- where xx in (...) 循环 selectKey