<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属性找不到的错误
本文详细解析了如何使用SQL语句进行数据更新和插入操作,包括使用IF语句判断数据是否存在并进行相应的操作,以及在更新操作中处理自定义对象中的属性。
9630

被折叠的 条评论
为什么被折叠?



