MyBatis实现SaveOrUpdate
<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>
注意如果insert的parameterType是自定义对象的话,对象里需要有count属性,否则会报count属性找不到的错误
页:
[1]