Example usage for org.apache.ibatis.session SqlSession selectList

List of usage examples for org.apache.ibatis.session SqlSession selectList

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession selectList.

Prototype

<E> List<E> selectList(String statement);

Source Link

Document

Retrieve a list of mapped objects from the statement key and parameter.

Usage

From source file:action.findDriver.java

public List<postasdriver> findlist() throws IOException {

    //connect database
    String resource = "orm/configuration.xml";
    Reader reader = Resources.getResourceAsReader(resource);
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession session = sessionFactory.openSession();

    try {//from www . ja v  a2 s . c o m

        postlist = session.selectList("selectAllPostAsDriver");
        System.out.println("postlist size=" + postlist.size());
        return postlist;

    } finally {
        session.close();
    }

}

From source file:am.client.MyFrame.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    //  ? ?? ../*from w ww  . j av a 2s  . c om*/
    SqlSession ss = factory.openSession();

    List<EmpVO> list = ss.selectList("emp_rel.all");

    //   
    viewData(list);
}

From source file:cl.beans.ContactoBean.java

public List<Contacto> getContactos() {
    List<Contacto> lista = null;
    SqlSession session = new MyBatisUtil().getSession();
    if (session != null) {
        try {/*w w w . ja v  a  2 s  . c o m*/
            lista = session.selectList("Contacto.obtenerContactos"); //el nombre del namespace

        } finally {
            session.close();
        }
    } else {
        System.out.println("Error");
    }
    return lista;
}

From source file:cn.songxinqiang.study.mybatis.test.HelloMyBatis.java

License:Apache License

public static void main(String[] args) throws IOException {
    // mybatis?/*from   www .  ja  va2  s  . c om*/
    String resource = "conf.xml";
    // mybatis??
    // InputStream is = HelloMyBatis.class.getClassLoader().getResourceAsStream(resource);
    // sqlSession
    // SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is);
    // MyBatis??Resourcesmybatis??
    Reader reader = Resources.getResourceAsReader(resource);
    // sqlSession
    SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(reader);
    // sqlsqlSession
    SqlSession session = sessionFactory.openSession();
    /**
     * sql
     * mapper.userMapperuserMapper.xmlmappernamespace
     * getUserselectidselectid??SQL
     */
    String statement = "mapper.userMapper.getUser";// sql
    // usersql
    User user = session.selectOne(statement, 2);
    System.out.println(user);

    statement = "mapper.userMapper.listUser";// sql
    List<User> users = session.selectList(statement);
    System.out.println(users);
}

From source file:com.albertzhe.mybatis_helloworld.mapper.impl.AdminMapperImpl.java

public List<Admin> getAllAdmins() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    List<Admin> admins = null;

    try {//from  w w w .  jav  a 2s . c o m
        admins = sqlSession.selectList("com.albertzhe.mybatis_helloworld.mapper.AdminMapper.getAllAdmins");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        sqlSession.close();
    }

    return admins;
}

From source file:com.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java

License:Apache License

protected final void testAndVerifySelectList() throws Exception {
    // Given/*from w  w  w.j a  v  a 2s .  co  m*/
    final String selectListId = "selectListId";
    SqlSession sqlSession = getSqlSession();
    // When
    sqlSession.selectList(selectListId);
    sqlSession.selectList(selectListId, new Object());
    sqlSession.selectList(selectListId, new Object(), RowBounds.DEFAULT);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method selectList1 = sqlSession.getClass().getDeclaredMethod("selectList", String.class);
    Method selectList2 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class);
    Method selectList3 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class,
            RowBounds.class);
    verifier.verifyTrace(event("MYBATIS", selectList1, Expectations.cachedArgs(selectListId)));
    verifier.verifyTrace(event("MYBATIS", selectList2, Expectations.cachedArgs(selectListId)));
    verifier.verifyTrace(event("MYBATIS", selectList3, Expectations.cachedArgs(selectListId)));
}

From source file:com.company.project.service.UserMapperImpl.java

License:Apache License

@Override
public List getAll() {
    SqlSession session = sqlSessionFactory.openSession();
    try {/*from  w w  w .j a v  a2  s .  com*/
        return session.selectList("com.company.project.persistence.UserMapper.getAll");
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        session.close();
    }

    return null;
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.BaseDao.java

License:Apache License

public List<T> getAll(String key) {
    try {/*from www .ja va 2s  . co m*/
        SqlSession session = getSqlSession();
        return session.selectList(key);
    } catch (Exception e) {
        logger.error(getClass().getName() + " getAll exception and key is" + key, e);
        return null;
    }
}

From source file:com.github.pagehelper.test.basic.PageHelperTest.java

License:Open Source License

@Test
public void shouldGetAllCountries() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {/*from  ww  w.  j  a va2  s.c  o m*/
        List<Country> list = sqlSession.selectList("selectAll");
        assertEquals(183, list.size());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.basic.PageHelperTest.java

License:Open Source License

/**
 * ??PageHelper.startPage// w ww . j  av a2 s.  c om
 * <p/>
 * startPage??(true)?(false)countstartPagecount
 * <p/>
 * startPage?RowBoundsstartPage
 */
@Test
public void testNamespaceWithStartPage() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();

    try {
        //?110?count
        PageHelper.startPage(1, 10);
        List<Country> list = sqlSession.selectList("selectAll");
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());

        //?210??count
        PageHelper.startPage(2, 10, true);
        list = sqlSession.selectList("selectAll");
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());

        //?210??count
        PageHelper.startPage(2, 10, false);
        list = sqlSession.selectList("selectAll");
        assertEquals(10, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());

        //?320?count
        PageHelper.startPage(3, 20);
        list = sqlSession.selectList("selectAll");
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
    } finally {
        sqlSession.close();
    }
}