MyBatis实现SaveOrUpdate

id="saveOrUpdate" >
  "id" resultType="com.piaoniu.entity.Country" order="BEFORE">
    select count(id) as id from country where name = #{name}
  
  <if test="id == 1">
    update country 
    set countryname = #{countryname},countrycode = #{countrycode} 
    where name = #{name}
  if>
  <if test="id == 0">
    insert into country values(#{name},#{countryname},#{countrycode})
  if>

你可能感兴趣的:(mybatis,mybatis)