核心是用Mybatis的foreach
<foreach collection="someList" item="someItem" ...>
</foreach>
1
批量查询:入参为List,包装在Map中,参考:http://blog.csdn.net/lxxxzzl/article/details/46376023
List<String> queryNamesByIds(Map<String, Object> userIdsParam);
<select id="queryNamesByIds" resultType="java.lang.String">
SELECT name from user
WHERE id in
<foreach collection="userIds" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
2
批量插入:
void batchInsert(List<AcctLoanInfo> acctInfoList);
<insert id="batchInsert" parameterType="java.util.List">
INSERT INTO USER_OPERATE_RECORD
(
<include refid="Columns_For_Insert"/>
)
VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.userAccountId,jdbcType=VARCHAR}, #{item.requestParameter,jdbcType=VARCHAR},
#{item.operateType,jdbcType=INTEGER}, #{item.gmtCreate,jdbcType=TIMESTAMP}
)
</foreach>
</insert>