码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis实现SaveOrUpdate

时间:2018-12-13 19:28:24      阅读:348      评论:0      收藏:0      [点我收藏+]

标签:insert   rup   tty   ==   test   class   before   count   mybatis   

例子

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

 

csdn上的代码,唯一必须注意的是 keyProperty="count" ,要在实体类dto里面有

<selectKey keyProperty="count" resultType="int" order="BEFORE">
    select count(*) from country where id = #{id}
  </selectKey>

 

MyBatis实现SaveOrUpdate

标签:insert   rup   tty   ==   test   class   before   count   mybatis   

原文地址:https://www.cnblogs.com/ydymz/p/10115462.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!