vagabond1-1983 / blog

My tech blog for achieve
GNU General Public License v2.0
2 stars 0 forks source link

【转】【Java之Mybatis】动态SQL #38

Open vagabond1-1983 opened 8 years ago

vagabond1-1983 commented 8 years ago

转:http://limingnihao.iteye.com/blog/782190 if test -- 检测值是否符合条件 foreach -- where xx in (...) 循环 selectKey

<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>