逆向生成的文件
测试dao与数据库之间是否连通
如果要批量处理
首先要在spring-mybatis.xml文件中注册
<!--配置一个可以执行批量的sqlSession -->
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
<constructor-arg name="executorType" value="BATCH"/>
</bean>
这样可以批量处理
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:resources/spring-*.xml"})
public class TestEnvirmoments {
@Autowired
CityMapper citymapper;
//注入可以批量操作的sqlSession
@Autowired
SqlSession sqlSession;
@Test
public void test(){
List<City> findAllCity = citymapper.findAllCity(3);
System.out.println(findAllCity);
ProvinceMapper mapper = sqlSession.getMapper(ProvinceMapper.class);
//将生成的uuid作为城市名
String uid=UUID.randomUUID().toString();
//截取
String uidStr = uid.substring(0, 2);
for(int i=0;i<50;i++){
mapper.insert(new Province(i+6,uidStr+i));
}
System.out.println("插入完成");
}
}