Mybatis 新增修改一条SQL

如果在INSERT语句末尾指定了ON DUPLICATE KEY UPDATE,并且插入行后会导致在一个UNIQUE索引或PRIMARY KEY中出现重复值,则执行旧行UPDATE;如果不会导致唯一值列重复的问题,则插入新行。例如,如果列a被定义为UNIQUE,并且包含值1,则以下 两个语句具有相同的效果:

<insert id="updateByProviderLotterytype" parameterType=" 参数">
INSERT INTO sc_provider_lotterytype (

relate_code,

buss_id,

buss_lotterytype,

lottery_typecode,

status,deal_by,

deal_time,

last_update_by

,last_update_time)   

 

VALUES (

#{relateCode},

#{bussId},

#{bussLotterytype},

#{lotteryTypecode},

#{status},#{dealBy},

#{dealTime},

#{lastUpdateBy},

#{lastUpdateTime})

 

ON DUPLICATE KEY UPDATE

buss_id = #{bussId},

buss_lotterytype = #{bussLotterytype},

lottery_typecode = #{lotteryTypecode},

status = #{status},
deal_by = #{dealBy},

deal_time = #{dealTime},

last_update_by = #{lastUpdateBy},

last_update_time = #{lastUpdateTime}
</insert>

 

很明显,以上 relate_code 字段就是主键,应为update时没有这个字段

posted @ 2015-01-28 21:14  iHoon  阅读(1026)  评论(0编辑  收藏  举报