package com.github.abel533.test.mysql;

import com.github.abel533.entity.Example;
import com.github.abel533.mapper.CountryMapper;
import com.github.abel533.mapper.MybatisHelper;
import com.github.abel533.model.Country;
import org.apache.ibatis.exceptions.PersistenceException;
import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * 通过实体类属性进行插入
 *
 * @author liuzh
 */
public class TestInsertList {

    /**
     * 插入完整数据
     */
    @Test
    public void testInsert() {
        SqlSession sqlSession = MybatisHelper.getSqlSession();
        try {
            CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
            List<Country> countryList = new ArrayList<Country>();
            for (int i = 0; i < 10; i++) {
                Country country = new Country();
                country.setId(10086 + i);
                country.setCountrycode("CN" + i);
                country.setCountryname("天朝" + i);
                countryList.add(country);
            }
            int count = mapper.insertList(countryList);
            Assert.assertEquals(10, count);


            Example example = new Example(Country.class);
            example.createCriteria().andGreaterThanOrEqualTo("id",10086);
            List<Country> list = mapper.selectByExample(example);

            Assert.assertEquals("CN2",list.get(2).getCountrycode());
        } finally {
            sqlSession.rollback();
            sqlSession.close();
        }
    }
}

@@ -216,66 +216,8 @@
 ry;%0A
-import org.apache.ibatis.exceptions.PersistenceException;%0A
 impo
@@ -285,31 +285,8 @@
 ert;
-%0Aimport org.junit.Test;
 %0A%0Aim
@@ -443,16 +443,52 @@
  */%0A    
+//%E8%AF%A5%E6%96%B9%E6%B3%95%E6%B5%8B%E8%AF%95%E9%9C%80%E8%A6%81mysql%E6%88%96%E8%80%85h2%E6%95%B0%E6%8D%AE%E5%BA%93%EF%BC%8C%E6%89%80%E4%BB%A5%E8%BF%99%E9%87%8C%E6%B3%A8%E9%87%8A%E6%8E%89%0A    //
 @Test%0A  

注释mysql的测试代码。