SSM-数据批量添加测试


首先在spring配置文件(applicationContext.xml)中添加

<!-- 配置一个可以执行批量的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>

然后看测试类:

    EmployeeMapper mapper=sqlSession.getMapper(EmployeeMapper.class);
        
        long starttime=System.currentTimeMillis(); System.out.println("批量添加开始:"+starttime); for(int i=0;i<1000;i++) { String str=UUID.randomUUID().toString().substring(0, 6)+i; mapper.insert(new Employee(null, str, "M", str+"@qq.com",nums[random.nextInt(nums.length-1)])); } long endtime=System.currentTimeMillis(); System.out.println("批量添加执行成功"+endtime+"总耗时:"+(endtime-starttime)); 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM