???????????????????????????????????????????????????????SQL??仹????????????Mybatis?????????????????????????Щ????????????Mybatis??????????????????н????
????1. ???????? Java????
????// Model: Test.java
????@Data
????public class Test {
????private String x;
????private String y;
????private String z;
????}
????// Mapper: TestMapper.java
????public void insertTestList(List<Test> testList);
????XML????
????<!-- XML: TestMapper.XML -->
????...
????<!-- ??????????? -->
????<insert id="insertTestList" parameterType="Test">
????INSERT IGNORE INTO
????test_table(test_x?? test_y?? test_z)
????VALUES
????<foreach item="item" index="index" collection="list" open="(" close=")" separator="??">
????#{item}.x?? #{item.y}?? #{item}.z
????</foreach>
????</insert>
????<!-- ??????????? -->
????<insert id="insertTestList" parameterType="Test">
????INSERT INTO
????test_table(test_x?? test_y?? test_z)
????VALUES
????<foreach item="item" index="index" collection="list" open="(" close=")" separator="??">
????#{item}.x?? #{item.y}?? #{item}.z
????</foreach>
????ON DUPLICATE KEY UPDATE
????test_x = VALUES(test_x)??
????test_y = VALUES(test_y)??
????test_z = VALUES(test_z)
????</insert>
????...
????????????SQL???
????insert into test_table(x?? y?? z) values (1?? 1?? 1)?? (2?? 2?? 2)?? (3?? 3?? 3)
????**?????**VALUE()??Mysql?????????????????????????function_values??
?????????????????????????????????μ????
????2. ??????? Java????
????// Model: Test.java
????@Data
????public class Test {
????private String x;
????private String y;
????private String z;
????}
????// Mapper: TestMapper.java
????public void deleteTestList(List<Test> testList);
????XML????
????<!-- XML: TestMapper.XML -->
????...
????<delete id="deleteTestList" parameterType="Test">
????DELETE FROM
????test_table
????WHERE
????<foreach item="item" index="index" collection="list" open="(" close=")" separator="OR">
????test_x = #{item.x} AND test_y = #{item.y} AND test_z = #{item.z}
????</foreach>
????</delete>
????...
????SQL???
????delete from test_table where (test_x = 1 AND test_y = 1 AND test_z = 1) or (test_x = 2 AND test_y = 2 AND test_z = 2) or (test_x = 3 AND test_y = 3 AND test_z = 3)
??????????????????x??y??z?????????????????????????where id in??