标签:art user 使用 tsql map limit 语句 use shm
为什么分页?
减少数据的处理量
核心sql语句:
<select id="getUserLimit" resultType="User" parameterType="map"> select *from mybatis.user limit ${startIndex},${pageSize}; </select>
接口
//使用limit实现分页 List<User> getUserLimit(Map<String,Integer> map);
Mapper.xml
<select id="getUserLimit" resultType="User" parameterType="map"> select *from mybatis.user limit ${startIndex},${pageSize}; </select>
测试
@Test public void testgetUserLimit(){ SqlSession sqlSession = MybatisUtils.getSqlSession(); UserMapper mapper = sqlSession.getMapper(UserMapper.class); Map<String,Integer> map = new HashMap<>(); map.put("startIndex",0); map.put("pageSize",2); ? ? List<User> users = mapper.getUserLimit(map); for (User user:users){ ? System.out.println(user); } sqlSession.close(); }
接口
//使用RowBounds分页 List<User> getUserByRowBounds();
<select id="getUserByRowBounds" resultType="User"> select * from user; </select>
测试
@Test public void testgerUserByRowBounds(){ ? RowBounds rowBounds = new RowBounds(1,2); SqlSession sqlSession = MybatisUtils.getSqlSession(); List<User> list = sqlSession.selectList("com.aishimin.dao.UserMapper.getUserByRowBounds", null, rowBounds); ? for(User user:list){ System.out.println(user); } ? sqlSession.close(); }
标签:art user 使用 tsql map limit 语句 use shm
原文地址:https://www.cnblogs.com/aishimin/p/14423786.html