Mybatis loop List

The first step , Mapper.java interface

void subInsert(List<Map<String, String>> list);

The second step , the corresponding statement tag:

<!-- ==================================批量插入记录================================== -->
	<insert id="subInsert" parameterType="java.util.Map">
		INSERT INTO table_name
		(id,start_time,balance)VALUES
		<foreach collection="list" item="item" separator=",">
			(
			NULL,
			#{item.start_time},
			#{item.balance}
			)
		</foreach>
	</insert>

The third step , add &allowMultiQueries=TRUE to the jdbc link, because Mabatis does not support writing multiple SQLs for one statement tag by default. The case is as follows:

jdbc.url=jdbc:mysql://192.168.1.110/data_test?useUnicode=TRUE&characterEncoding=utf-8&allowMultiQueries=TRUE

Guess you like

Origin blog.csdn.net/m0_54850604/article/details/123670923