1. 程式人生 > >mybatis實現hibernate的saveOrUpdate

mybatis實現hibernate的saveOrUpdate

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

="count>0"> 

         <include refid="updateByPrimaryKeySelective" />

     </if>

<if test="count==0">

     <include refid="insertSelective" />

</if>

  </insert>

TestCardInf類中增加屬性:

private Integer count;