xml配置:
class="java"> <insert id="insertWinePrice" parameterType="java.util.Map">
insert into wineprice (id,price,time) VALUES
<foreach collection="params.keys" item="key" open="(" separator=",">
${key}
</foreach>
,
<foreach collection="params.values" item="v" close=")" separator=",">
#{v.m},#{v.p}
</foreach>
</insert>
接口代码:
public void insertWinePrice(@Param("params") Map<Integer,JdWinePo> map);
测试代码:
Reader reader = Resources.getResourceAsReader("config/conf.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
SqlSession sqlSession = factory.openSession();
JdMapper jm = sqlSession.getMapper(JdMapper.class);
Map<Integer,JdWinePo> map = new HashMap<Integer, JdWinePo>();
JdWinePo j = new JdWinePo();
j.setId("3232");
j.setM("erwewr");
j.setOp("fsaeet");
j.setP("4343");
map.put(212112,j);
jm.insertWinePrice(map);
sqlSession.commit();
sqlSession.close();
这里我的
理解。xml配置生成sql语句不能生成批量sql语句,所有的批量sql,只能在业务逻辑代码处进行处理。