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