首页 > 其他 > 详细

MyBatis实现SaveOrUpdate

时间:2018-12-13 18:55:11      阅读:611      评论:0      收藏:0      [点我收藏+]

例子

<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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!