insert into country (countryname,countrycode) values (#{country.countryname},#{country.countrycode})
@Test public void shouldInsertListAndRetrieveId() throws Exception { Reader reader = Resources.getResourceAsReader("org/apache/ibatis/executor/keygen/MapperConfig.xml"); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); SqlSession sqlSession = sqlSessionFactory.openSession(); try { CountryMapper mapper = sqlSession.getMapper(CountryMapper.class); Listcountries = new ArrayList (); countries.add(new Country("China", "CN")); countries.add(new Country("United Kiongdom", "GB")); countries.add(new Country("United States of America", "US")); mapper.insertList(countries); for (Country country : countries) { assertNotNull(country.getId()); } } finally { sqlSession.rollback(); sqlSession.close(); } }
具体修复参见:https://github.com/mybatis/mybatis-3/pull/547
相关参考文章:https://my.oschina.net/zudajun/blog/674946