SQL:根据主键判断如果不存在插入,存在更新

SQL:根据主键判断如果不存在插入,存在更新

<insert id="insertOrUpdate"  parameterType="Authshiming">
		insert into
		authshiming (
					authid ,
					paytype ,
					authmoney ,
					orderno,
					userid,
					authtype
					)
		values ( -- 如果主键不存在那么插入的内容
				#{authID},#{payType},#{authMoney},
				#{orderNo},#{userID},#{authType}
				)
		ON DUPLICATE KEY UPDATE -- 如果主键存在那么更新的内容
					paytype = #{payType},
					authmoney = #{authMoney},
					orderno= #{orderNo},
					userid= #{userID},
					authtype= #{authType},
					xingming_companyname = #{xingmingCompanyName},
					zhengjianno = #{zhengjianNo},
					zhengJianImg= #{zhengJianImg},
					phone = #{phone},
					shopname = #{shopName},
					province= #{province},
					city = #{city},
					area= #{area},
					address= #{address},
					latitude= #{latitude},
					longitude= #{longitude},
					paystate = #{payState},
					state= #{state},
					authdatetime= #{authDatetime},
					authFinishDatetime= #{authFinishDatetime},
					chatRoomID= #{chatRoomID},
					chatGroupsID= #{chatGroupsID},
					createtime= #{createtime},
					failMsg = #{failMsg},
					logoUrl= #{logoUrl}
	</insert>
posted @ 2019-01-19 20:50  yabushier  阅读(1832)  评论(0)    收藏  举报