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>

猜你喜欢

转载自www.cnblogs.com/yabushier/p/10293213.html