Example usage for org.apache.ibatis.session RowBounds RowBounds

List of usage examples for org.apache.ibatis.session RowBounds RowBounds

Introduction

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

Prototype

public RowBounds(int offset, int limit) 

Source Link

Usage

From source file:com.github.pagehelper.rowbounds.test.RowBoundsTest.java

License:Open Source License

@Test
public void testNamespaceWithRowBounds2() {
    SqlSession sqlSession = RowBoundsHelper.getSqlSession();
    try {//  w w  w  .ja  v a  2s  . c om
        //?010?
        List<Country> list = sqlSession.selectList("selectIf", null, new RowBounds(0, 10));
        assertEquals(10, list.size());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.get(list.size() - 1).getId());

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", 10);
        //?1010?
        list = sqlSession.selectList("selectIf", map, new RowBounds(90, 10));
        assertEquals(10, list.size());
        //??
        assertEquals(101, list.get(0).getId());
        assertEquals(110, list.get(list.size() - 1).getId());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.rowbounds.test.RowBoundsTest.java

License:Open Source License

/**
 * Mapper?PageHelper.startPage??Mapper??
 *//*from   w w w  . j  ava  2s  .co  m*/
@Test
public void testWithRowboundsAndCountTrue() {
    SqlSession sqlSession = RowBoundsHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //limit=0,?count,????rounbounds?count?-1
        //?-1
        List<Country> list = countryMapper.selectAll(new RowBounds(0, -1));
        assertEquals(183, list.size());

        //pageSize<0?
        list = countryMapper.selectAll(new RowBounds(0, -100));
        assertEquals(183, list.size());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * Mapper??RowBounds???xml??/*from   ww  w . java2  s . c  om*/
 * <p/>
 * RowBounds??count?Page?
 * <p/>
 * ??startPagestartPage
 */
@Test
public void testMapperWithRowBounds() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //?110?count
        List<Country> list = countryMapper.selectAll(new RowBounds(0, 10));
        assertEquals(10, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.get(list.size() - 1).getId());

        //?210??count
        list = countryMapper.selectAll(new RowBounds(10, 10));
        assertEquals(10, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(11, list.get(0).getId());
        assertEquals(20, list.get(list.size() - 1).getId());

        //?320?count
        list = countryMapper.selectAll(new RowBounds(60, 20));
        assertEquals(20, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(61, list.get(0).getId());
        assertEquals(80, list.get(list.size() - 1).getId());

        //?startPageRowBoundsstartPage
        PageHelper.startPage(1, 20);
        list = countryMapper.selectAll(new RowBounds(60, 20));
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(20, list.get(list.size() - 1).getId());
    } finally {
        sqlSession.close();
    }
}

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

License:Open Source License

/**
 * ???RowBoundsRowBounds?count//from  ww w .  ja v  a2 s .c  om
 * ??count??
 * ?count?startPage
 * <p/>
 * ?startPagestartPage?startPage??
 */
@Test
public void testNamespaceWithRowBounds() {
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    try {
        //?010?
        List<Country> list = sqlSession.selectList("selectAll", null, new RowBounds(0, 10));
        assertEquals(10, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.get(list.size() - 1).getId());

        //?1010?
        list = sqlSession.selectList("selectAll", null, new RowBounds(10, 10));
        assertEquals(10, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(11, list.get(0).getId());
        assertEquals(20, list.get(list.size() - 1).getId());

        //?2020?
        list = sqlSession.selectList("selectAll", null, new RowBounds(20, 20));
        assertEquals(20, list.size());
        assertEquals(-1, ((Page<?>) list).getTotal());
        //??
        assertEquals(21, list.get(0).getId());
        assertEquals(40, list.get(list.size() - 1).getId());

        //?startPageRowBoundsstartPage
        PageHelper.startPage(1, 20);
        list = sqlSession.selectList("selectAll", null, new RowBounds(0, 10));
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(20, list.get(list.size() - 1).getId());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.namespace.BasicTest.java

License:Open Source License

@Test
public void testNamespace1() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    try {/* ww  w  . ja va2 s . c o m*/
        Map<String, Object> map = new HashMap<String, Object>();
        Country country = new Country();
        country.setCountryname("China");
        map.put("country", country);
        //????Map
        map = Collections.unmodifiableMap(map);
        List<Country> list = sqlSession.selectList("select1", map, new RowBounds(1, 10));
        assertEquals(1, list.size());
        //??
        assertEquals(35, list.get(0).getId());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.namespace.BasicTest.java

License:Open Source License

@Test
public void testNamespace3() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    try {/*  w  ww  .  j  av  a 2  s  . c  o m*/
        Map<String, Object> map = new HashMap<String, Object>();
        Country country = new Country();
        map.put("country", country);
        //????Map
        map = Collections.unmodifiableMap(map);
        List<Country> list = sqlSession.selectList("select1", map, new RowBounds(1, 10));
        assertEquals(10, list.size());
        //??
        assertEquals(1, list.get(0).getId());

        map = new HashMap<String, Object>();
        country = new Country();
        country.setCountryname("China");
        map.put("country", country);
        //????Map
        map = Collections.unmodifiableMap(map);
        list = sqlSession.selectList("select1", map, new RowBounds(1, 10));
        assertEquals(1, list.size());
        //??
        assertEquals(35, list.get(0).getId());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.pagesize.PageSizeLessThenOrEqualZeroTest.java

License:Open Source License

/**
 * Mapper?PageHelper.startPage??Mapper??
 *///from w  w w  .  j  a  v a  2  s  . c o  m
@Test
public void testWithRowbounds() {
    //?MybatisRowBoundsHelpercount
    SqlSession sqlSession = MybatisHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //limit=0,?count,????rounbounds?count?-1
        List<Country> list = countryMapper.selectAll(new RowBounds(1, 0));
        PageInfo<Country> page = new PageInfo<Country>(list);
        assertEquals(0, list.size());
        assertEquals(-1, page.getTotal());

        //limit<0?
        list = countryMapper.selectAll(new RowBounds(1, -100));
        page = new PageInfo<Country>(list);
        assertEquals(0, list.size());
        assertEquals(-1, page.getTotal());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.pagesize.PageSizeZeroTest.java

License:Open Source License

/**
 * Mapper?PageHelper.startPage??Mapper??
 *//*from  w w  w  .  ja va 2  s  .co m*/
@Test
public void testWithRowbounds() {
    SqlSession sqlSession = MybatisPageSizeZeroHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //pageSize=0
        List<Country> list = countryMapper.selectAll(new RowBounds(1, 0));
        PageInfo<Country> page = new PageInfo<Country>(list);
        assertEquals(183, list.size());
        assertEquals(183, page.getTotal());

        //pageSize=0
        PageHelper.startPage(10, 0);
        list = countryMapper.selectAll(new RowBounds(1000, 0));
        page = new PageInfo<Country>(list);
        assertEquals(183, list.size());
        assertEquals(183, page.getTotal());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.rowbounds.RowBoundsTest.java

License:Open Source License

/**
 * Mapper??RowBounds???xml??/*  ww  w . j a v a  2s.co m*/
 * <p/>
 * RowBounds??count?Page?
 * <p/>
 * ??startPagestartPage
 */
@Test
public void testMapperWithRowBounds() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    CountryMapper countryMapper = sqlSession.getMapper(CountryMapper.class);
    try {
        //?110?count
        List<Country> list = countryMapper.selectAll(new RowBounds(1, 10));
        //PageInfo?
        PageInfo<Country> page = new PageInfo<Country>(list);
        assertEquals(10, list.size());
        assertEquals(183, page.getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.get(list.size() - 1).getId());

        //?1010??count
        list = countryMapper.selectAll(new RowBounds(10, 10));
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(91, list.get(0).getId());
        assertEquals(100, list.get(list.size() - 1).getId());

        //?320?count
        list = countryMapper.selectAll(new RowBounds(6, 20));
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(101, list.get(0).getId());
        assertEquals(120, list.get(list.size() - 1).getId());
    } finally {
        sqlSession.close();
    }
}

From source file:com.github.pagehelper.test.rowbounds.RowBoundsTest.java

License:Open Source License

/**
 * ???RowBoundsRowBounds?count/* www .j  a  va 2  s .c  o  m*/
 * ??count??
 * ?count?startPage
 * <p/>
 * ?startPagestartPage?startPage??
 */
@Test
public void testNamespaceWithRowBounds() {
    SqlSession sqlSession = MybatisRowBoundsHelper.getSqlSession();
    try {
        //?010?
        List<Country> list = sqlSession.selectList("selectAll", null, new RowBounds(1, 10));
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(1, list.get(0).getId());
        assertEquals(10, list.get(list.size() - 1).getId());

        //?1010?
        list = sqlSession.selectList("selectAll", null, new RowBounds(10, 10));
        assertEquals(10, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(91, list.get(0).getId());
        assertEquals(100, list.get(list.size() - 1).getId());

        //?2020?
        list = sqlSession.selectList("selectAll", null, new RowBounds(6, 20));
        assertEquals(20, list.size());
        assertEquals(183, ((Page<?>) list).getTotal());
        //??
        assertEquals(101, list.get(0).getId());
        assertEquals(120, list.get(list.size() - 1).getId());
    } finally {
        sqlSession.close();
    }
}