mybatis實現hibernate的saveOrUpdate
阿新 • • 發佈:2018-12-17
mapper配置檔案中配置sql:
<insert id="saveOrUpdateObject" parameterType="TestCardInf">
<selectKey keyProperty="count" resultType="int" order="BEFORE">
select count(1) as count from t_test_card where AGREE_NO = #{agreeNo} with ur
</selectKey>
<if test
<include refid="updateByPrimaryKeySelective" />
</if>
<if test="count==0">
<include refid="insertSelective" />
</if>
</insert>
TestCardInf類中增加屬性:
private Integer count;