Java Code Examples for org.apache.ibatis.session.SqlSession

The following examples show how to use org.apache.ibatis.session.SqlSession. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mybaties   Source File: ComplexTypeTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/complex_type/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example 2
Source Project: mybatis   Source File: SPTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAdderAsSelectDoubleCall2() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Parameter parameter = new Parameter();
    parameter.setAddend1(2);
    parameter.setAddend2(3);

    SPMapper spMapper = sqlSession.getMapper(SPMapper.class);

    spMapper.adderAsSelect(parameter);
    assertEquals((Integer) 5, parameter.getSum());

    parameter = new Parameter();
    parameter.setAddend1(4);
    parameter.setAddend2(5);
    spMapper.adderAsSelect(parameter);
    assertEquals((Integer) 9, parameter.getSum());

  } finally {
    sqlSession.close();
  }
}
 
Example 3
Source Project: mybatis   Source File: CustomCollectionHandlingTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Custom collections with nested resultMap.
 *
 * @throws Exception
 */
@Test
public void testSelectListWithNestedResultMap() throws Exception {
    String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
    SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithResultMap");
        assertEquals(2, list.size());
        assertEquals(2, list.get(0).getContacts().size());
        assertEquals(1, list.get(1).getContacts().size());
        assertEquals("3 Wall Street", list.get(0).getContacts().get(1).getAddress());
    } finally {
        sqlSession.close();
    }
}
 
Example 4
Source Project: Mapper   Source File: TestTransient.java    License: MIT License 6 votes vote down vote up
/**
 * 插入完整数据
 */
@Test
public void testDynamicInsert() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryTMapper mapper = sqlSession.getMapper(CountryTMapper.class);
        CountryT country = new CountryT();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("天朝");
        Assert.assertEquals(1, mapper.insert(country));

        //查询CN结果
        country = new CountryT();
        country.setCountrycode("CN");
        List<CountryT> list = mapper.select(country);

        Assert.assertEquals(2, list.size());
        //屏蔽的数据是null
        Assert.assertNull(list.get(0).getCountrycode());
        //删除插入的数据,以免对其他测试产生影响
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}
 
Example 5
Source Project: tk-mybatis   Source File: TestUserLogin2.java    License: MIT License 6 votes vote down vote up
/**
 * 主要测试删除
 */
@Test
public void testDelete() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserLogin2Mapper mapper = sqlSession.getMapper(UserLogin2Mapper.class);
        //查询总数
        Assert.assertEquals(10, mapper.selectCount(new UserLogin2()));
        //根据主键查询
        UserLogin2Key key = new UserLogin2();
        key.setLogid(1);
        key.setUsername("test1");
        UserLogin2 userLogin = mapper.selectByPrimaryKey(key);
        //根据主键删除
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(key));

        //查询总数
        Assert.assertEquals(9, mapper.selectCount(new UserLogin2()));
        //插入
        Assert.assertEquals(1, mapper.insert(userLogin));
    } finally {
        sqlSession.close();
    }
}
 
Example 6
Source Project: tk-mybatis   Source File: TestIndentity.java    License: MIT License 6 votes vote down vote up
/**
 * 插入完整数据
 */
@Test
public void testINDENTITYInsert2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryIMapper mapper = sqlSession.getMapper(CountryIMapper.class);
        CountryI country = new CountryI();
        country.setId(10086);
        country.setCountrycode("CN");
        country.setCountryname("天朝");
        Assert.assertEquals(1, mapper.insert(country));

        //查询CN结果
        country = new CountryI();
        country.setCountrycode("CN");
        List<CountryI> list = mapper.select(country);

        Assert.assertEquals(1, list.size());
        Assert.assertNotNull(list.get(0).getCountryname());
        Assert.assertEquals("天朝", list.get(0).getCountryname());
        //删除插入的数据,以免对其他测试产生影响
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(10086));
    } finally {
        sqlSession.close();
    }
}
 
Example 7
@BeforeClass
public static void setUp() throws Exception {
  // create an SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example 8
Source Project: tk-mybatis   Source File: TestInsert.java    License: MIT License 6 votes vote down vote up
/**
 * 插入空数据,id不能为null,会报错
 */
@Test
public void testDynamicInsertAll() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        Country2Mapper mapper = sqlSession.getMapper(Country2Mapper.class);
        Country2 country2 = new Country2();
        country2.setCountrycode("CN");
        country2.setId(100);
        Assert.assertEquals(1, mapper.insert(country2));

        country2 = mapper.select(country2).get(0);
        Assert.assertNotNull(country2);

        Assert.assertEquals(1, mapper.deleteByPrimaryKey(country2.getId()));

    } finally {
        sqlSession.close();
    }
}
 
Example 9
Source Project: Mybatis-PageHelper   Source File: OffsetTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testOffset() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        PageHelper.startPage(1, 6);
        List<User> list = userMapper.selectAll();
        assertEquals(6, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());

        PageHelper.offsetPage(6, 20);
        list = userMapper.selectAll();
        PageInfo<User> pageInfo = new PageInfo<User>(list);
        System.out.println(pageInfo.toString());
        assertEquals(2, ((Page<?>) list).getPageNum());
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
 
Example 10
Source Project: Mybatis-PageHelper   Source File: TestExists.java    License: MIT License 6 votes vote down vote up
/**
 * union的count查询sql特殊
 */
@Test
public void testExists() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
    try {
        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(1, 10);
        List<User> list = userMapper.selectExists();
        assertEquals(101, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(83, ((Page<?>) list).getTotal());

        //获取第1页,10条内容,默认查询总数count
        PageHelper.startPage(2, 10);
        list = userMapper.selectExists();
        assertEquals(111, list.get(0).getId());
        assertEquals(10, list.size());
        assertEquals(83, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}
 
Example 11
Source Project: mybaties   Source File: PrimitivesTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create an SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitives/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/primitives/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example 12
Source Project: mybatis   Source File: ForEachTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHandleComplexNullItem() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user1 = new User();
    user1.setId(2);
    user1.setName("User2");
    List<User> users = new ArrayList<User>();
    users.add(user1);
    users.add(null);
    int count = mapper.countByUserList(users);
    Assert.assertEquals(1, count);
  } finally {
    sqlSession.close();
  }
}
 
Example 13
Source Project: mybaties   Source File: NestedResultHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example 14
/**
 * 测试 logicalDeleteByPrimaryKey
 */
@Test
public void testLogicalDeleteByPrimaryKey() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator.xml");
    tool.generate(new AbstractShellCallback() {
        @Override
        public void reloadProject(SqlSession sqlSession, ClassLoader loader, String packagz) throws Exception{
            ObjectUtil tbMapper = new ObjectUtil(sqlSession.getMapper(loader.loadClass(packagz + ".TbMapper")));

            // 验证sql
            String sql = SqlHelper.getFormatMapperSql(tbMapper.getObject(), "logicalDeleteByPrimaryKey", 2l);
            Assert.assertEquals(sql, "update tb set del_flag = 1 where id = 2");
            // 验证执行
            Object result = tbMapper.invoke("logicalDeleteByPrimaryKey", 2l);
            Assert.assertEquals(result, 1);
            ResultSet rs = DBHelper.execute(sqlSession.getConnection(), "select del_flag from tb where id = 2");
            rs.first();
            Assert.assertEquals(rs.getInt("del_flag"), 1);
        }
    });
}
 
Example 15
Source Project: tk-mybatis   Source File: TestSelectByPrimaryKey.java    License: MIT License 6 votes vote down vote up
/**
 * 查询不存在的结果
 */
@Test
public void testDynamicSelectByPrimaryKeyZero() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Assert.assertNull(mapper.selectByPrimaryKey(new Country()));
        Assert.assertNull(mapper.selectByPrimaryKey(new HashMap<String,Object>()));
        Assert.assertNull(mapper.selectByPrimaryKey(-10));
        Assert.assertNull(mapper.selectByPrimaryKey(0));
        Assert.assertNull(mapper.selectByPrimaryKey(1000));
        Assert.assertNull(mapper.selectByPrimaryKey(null));
    } finally {
        sqlSession.close();
    }
}
 
Example 16
Source Project: tk-mybatis   Source File: TestTransient.java    License: MIT License 6 votes vote down vote up
/**
 * 根据查询条件进行查询
 */
@Test
public void testDynamicSelect() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryTMapper mapper = sqlSession.getMapper(CountryTMapper.class);
        CountryT country = new CountryT();
        country.setId(174);
        country.setCountrycode("US");
        List<CountryT> countryList = mapper.select(country);

        Assert.assertEquals(1, countryList.size());
        Assert.assertEquals(true, countryList.get(0).getId() == 174);
        Assert.assertNotNull(countryList.get(0).getCountryname());
        Assert.assertNull(countryList.get(0).getCountrycode());
    } finally {
        sqlSession.close();
    }
}
 
Example 17
Source Project: Mapper   Source File: TestExampleBuilder.java    License: MIT License 6 votes vote down vote up
@Test
public void testDistinct() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Example example = Example.builder(Country.class)
                .distinct()
                .build();
        List<Country> countries = mapper.selectByExample(example);
        Assert.assertEquals(183, countries.size());

        // distinct和order by冲突问题
        Example example0 = Example.builder(Country.class)
                .selectDistinct("id", "countryname").build();
        List<Country> countries0 = mapper.selectByExample(example0);
        Assert.assertEquals(183, countries0.size());
    } finally {
        sqlSession.close();
    }
}
 
Example 18
Source Project: mybaties   Source File: BlockingCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  // create a SqlSessionFactory
  Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blocking_cache/mybatis-config.xml");
  sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
  reader.close();

  // populate in-memory database
  SqlSession session = sqlSessionFactory.openSession();
  Connection conn = session.getConnection();
  reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/blocking_cache/CreateDB.sql");
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.runScript(reader);
  reader.close();
  session.close();
}
 
Example 19
Source Project: mybatis   Source File: DynSqlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDynamicSelectWithTypeHandler() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    List<Name> names = new ArrayList<Name>();

    Name name = new Name();
    name.setFirstName("Fred");
    name.setLastName("Flintstone");
    names.add(name);

    name = new Name();
    name.setFirstName("Barney");
    name.setLastName("Rubble");
    names.add(name);

    Parameter parameter = new Parameter();
    parameter.setNames(names);

    List<Map<String, Object>> answer = sqlSession.selectList("org.apache.ibatis.submitted.dynsql2.dynamicSelectWithTypeHandler", parameter);

    assertTrue(answer.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
Example 20
Source Project: Nickle-Scheduler   Source File: HeartBeatActor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 更新执行器时间
 *
 * @param sqlSession
 * @param heatBeatEvent
 */
private void updateExecutorTime(SqlSession sqlSession, HeatBeatEvent heatBeatEvent) {
    //更新主机
    NickleSchedulerExecutorMapper executorMapper = sqlSession.getMapper(NickleSchedulerExecutorMapper.class);
    String ip = heatBeatEvent.getIp();
    Integer port = heatBeatEvent.getPort();
    log.info("更新主机updateTime:{}", heatBeatEvent);
    int count = executorMapper.updateByIpAndPort(heatBeatEvent.getIp(), heatBeatEvent.getPort(), System.currentTimeMillis());
    if (count == 0) {
        log.info("主机已被删除,将再次增加主机");
        //插入主机
        Delegate.insertExecutor(sqlSession, ip, port);
        //插入关联表
        List<String> jobNameList = heatBeatEvent.getJobNameList();
        for (String jobName : jobNameList) {
            Delegate.insertExecutorJob(sqlSession, ip, port, jobName);
        }
    }
    //回复心跳信息
    getSender().tell(HEARTBEAT_OK, getSelf());
}
 
Example 21
Source Project: mybatis-action   Source File: SysUserMapperTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSelectRolesByUserAndRole() {
    SqlSession sqlSession = getSqlSession();

    try {
        SysUserMapper sysUserMapper = sqlSession.getMapper(SysUserMapper.class);

        SysUser sysUser = new SysUser();
        sysUser.setId(1L);
        SysRole sysRole = new SysRole();
        sysRole.setEnabled(Enabled.enabled);

        List<SysRole> sysRoleList = sysUserMapper.selectRolesByUserAndRole(sysUser, sysRole);

        Assert.assertNotNull(sysRoleList);
        Assert.assertTrue(sysRoleList.size() > 0);
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
Example 22
Source Project: mybaties   Source File: SelectKeyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAnnotatedUpdateTable2WithSelectKeyWithKeyMap() {
    SqlSession sqlSession = sqlSessionFactory.openSession();

    try {
      Name name = new Name();
      name.setName("barney");
      AnnotatedMapper mapper = sqlSession.getMapper(AnnotatedMapper.class);
      int rows = mapper.insertTable2WithSelectKeyWithKeyMap(name);
      assertEquals(1, rows);
      assertEquals(22, name.getNameId());
      assertEquals("barney_fred", name.getGeneratedName());
      
      name.setName("Wilma");
      rows = mapper.updateTable2WithSelectKeyWithKeyMap(name);
      assertEquals(1, rows);
      assertEquals(22, name.getNameId());
      assertEquals("Wilma_fred", name.getGeneratedName());
    } finally {
      sqlSession.close();
    }
}
 
Example 23
Source Project: Mapper   Source File: VersionTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdate() {
    SqlSession sqlSession = getSqlSession();
    try {
        UserTimestampMapper mapper = sqlSession.getMapper(UserTimestampMapper.class);
        UserTimestamp user = mapper.selectByPrimaryKey(999);
        assertNotNull(user);
        Timestamp joinDate = user.getJoinDate();
        int count = mapper.updateByPrimaryKey(user);
        assertEquals(1, count);

        user = mapper.selectByPrimaryKey(999);
        assertFalse(joinDate.equals(user.getJoinDate()));
    } finally {
        sqlSession.close();
    }
}
 
Example 24
Source Project: tk-mybatis   Source File: TestUpdateByExample.java    License: MIT License 6 votes vote down vote up
@Test
public void testUpdateByExample2() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        Country country = new Country();
        country.setCountryname("天朝");
        country.setId(1000);


        CountryExample example = new CountryExample();
        example.createCriteria().andIdEqualTo(35);
        int count = mapper.updateByExample(country, example);
        Assert.assertEquals(1, count);

        example = new CountryExample();
        example.createCriteria().andCountrycodeIsNull();
        count = mapper.selectCountByExample(example);
        Assert.assertEquals(1, count);
    } finally {
        sqlSession.rollback();
        sqlSession.close();
    }
}
 
Example 25
Source Project: tk-mybatis   Source File: TestDeleteByPrimaryKey.java    License: MIT License 6 votes vote down vote up
/**
 * 主要测试删除
 */
@Test
public void testDynamicDelete() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        //查询总数
        Assert.assertEquals(183, mapper.selectCount(new Country()));
        //查询100
        Country country = mapper.selectByPrimaryKey(100);
        //根据主键删除
        Assert.assertEquals(1, mapper.deleteByPrimaryKey(100));
        //查询总数
        Assert.assertEquals(182, mapper.selectCount(new Country()));
        //插入
        Assert.assertEquals(1, mapper.insert(country));
    } finally {
        sqlSession.close();
    }
}
 
Example 26
Source Project: oneops   Source File: OneopsCmsManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Gets the clazzes.
 *
 * @return the clazzes
 */
public List<CmsClazz> getClazzes() {
	SqlSession session = sqlSessionFactory.openSession();
	List<CmsClazz> clazzes;
	try {
		ClazzMapper mapper = session.getMapper(ClazzMapper.class);
		clazzes = mapper.getClazzes();
		for(CmsClazz clazz : clazzes) {
			clazz.setMdAttributes(mapper.getClazzAttrs(clazz.getClassId()));
			clazz.setFromRelations(mapper.getFromClazzRelations(clazz.getClassId()));
			clazz.setToRelations(mapper.getToClazzRelations(clazz.getClassId()));
		}
	} finally {
		session.close();
	}
	return clazzes;
}
 
Example 27
Source Project: mybatis-gson   Source File: PostgresqlTest.java    License: MIT License 5 votes vote down vote up
@Test
public void test3ReadNulls() {
    try (SqlSession sess = sessionFactory.openSession()) {
        JsonMapper mapper = sess.getMapper(JsonMapper.class);
        JsonEntity e1 = mapper.get(1);
        assertThat(e1.getJsonArray().isJsonNull()).isTrue();
        assertThat(e1.getJsonObject().isJsonNull()).isTrue();

        JsonEntity e2 = mapper.get(2);
        assertThat(e2.getJsonArray().isJsonNull()).isTrue();
        assertThat(e2.getJsonObject().isJsonNull()).isTrue();
    }
}
 
Example 28
Source Project: Mapper   Source File: SafeUpdateByFieldTest.java    License: MIT License 5 votes vote down vote up
@Test(expected = PersistenceException.class)
public void testSafeUpdate() {
    SqlSession sqlSession = getSqlSession();
    try {
        CountryMapper mapper = sqlSession.getMapper(CountryMapper.class);
        mapper.updateByExample(new Country(), new Example(Country.class));
    } finally {
        sqlSession.close();
    }
}
 
Example 29
Source Project: mybaties   Source File: MultipleIteratesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGetAUser() {
  SqlSession sqlSession = sqlSessionFactory.openSession();
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);
    User user = new User();
    user.setId(1);
    user.setName("Justin");
    user.setFirstAttr(new String[] { "asd", "asd" });
    user.setSecondAttr(new String[] { "fds", "fds" });
    mapper.insertUser(user);
  } finally {
    sqlSession.close();
  }
}
 
Example 30
Source Project: Mapper   Source File: TestUserLogin2.java    License: MIT License 5 votes vote down vote up
/**
 * 查询
 */
@Test
public void testSelect() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        UserLogin2Mapper mapper = sqlSession.getMapper(UserLogin2Mapper.class);
        UserLogin2 userLogin = new UserLogin2();
        userLogin.setUsername("test1");
        List<UserLogin2> userLogins = mapper.select(userLogin);
        Assert.assertEquals(5, userLogins.size());
    } finally {
        sqlSession.close();
    }
}