foreach 標(biāo)簽插入數(shù)據(jù)量大時(shí),明顯影響效率,個(gè)人傾向以下配置?
applicationcontext 配置文件
<!-- 批量執(zhí)行的sqlSession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"></constructor-arg>
<constructor-arg name="executorType" value="BATCH"></constructor-arg>
</bean>
Java代碼文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-531195.html
public class TestServiceImpl implements ITestService{
@Autowired
private SqlSession sqlSession;
public void test(){
List<Student> list = new ArrayList<>();
for (int i = 0; i < data.size(); i++) {
Student student = new Student();
student.setId(Utility.getUUID());
student.setIsDelete("0");
list.add(student);
}
//開(kāi)始批量入庫(kù)
SysTreeDicMapper mapper = sqlSession.getMapper(Student Mapper.class);
list.stream().forEach(o -> {
mapper.insertSelective(o);
});}
}
mybatis文件沒(méi)什么可說(shuō)的,就是普通單條插入的<insert> 標(biāo)簽即可文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-531195.html
到了這里,關(guān)于mybatis配置批量執(zhí)行SQL的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!