mabatis的XML文件写法
<insert id="saveIfNoExit" parameterType="pd">
INSERT INTO t_cluster_server (id,cluster_id,server_id)
SELECT
#{id},
#{clusterId},
#{serverId}
FROM
DUAL
WHERE NOT EXISTS (
SELECT
*
FROM
t_cluster_server
WHERE
t_cluster_server.cluster_id = #{clusterId} and
t_cluster_server.server_id = #{serverId}
);
</insert>
sql语句:
INSERT INTO t_cluster_server (
id,
cluster_id,
server_id
) SELECT
10345,
'IBM',
'advertising'
FROM
DUAL
WHERE
NOT EXISTS (
SELECT
*
FROM
t_cluster_server
WHERE
t_cluster_server.cluster_id = 'IBM' and
t_cluster_server.server_id = 'advertising'
);