MyBatis ON DUPLICATE KEY UPDATE用法
添加数据时根据主键进行比对,如果数据存在就更新,如果不存在就新增
<insert id="updateAndInsert" parameterType="com.codyy.ms.entity.IpAreaDO"> INSERT INTO IP_AREA (IP,AREA_NAME,AREA_CODE,UPDATE_TIME) VALUE (#{ip,jdbcType=VARCHAR}, #{areaName,jdbcType=VARCHAR}, #{areaCode,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}) ON DUPLICATE KEY UPDATE AREA_NAME = #{areaName,jdbcType=VARCHAR}, AREA_CODE = #{areaCode,jdbcType=VARCHAR}, UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP} </insert>