mybatis batch operate extension for spring
github:https://github.com/xiwasong/mybatis-batch
oschina:http://git.oschina.net/xiwa/mybatis-batch
SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
bean.setSqlSessionFactoryBuilder(new BatchSessionFactoryBuilder());
<insert id="insertCountries" parameterType="java.util.List">
insert into country (countryname, countrycode)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.name,jdbcType=VARCHAR},#{item.code,jdbcType=VARCHAR} )
</foreach>
</insert>
@Autowired
private SqlSessionTemplate template;
List<Country> countries=new ArrayList<Country>();
for(int i=0;i<count;i++){
countries.add(new Country("name"+i,"code"+i));
}
BatchParameterInfo batchParameterInfo=new BatchParameterInfo(countries);
template.insert("batch.insertCountries",batchParameterInfo) ;