标签:index ssi pre 处理 str help app select owb
为什么要分页?
语法:SELECT * FROM user LIMIT startIndex,pageSize;
SELECT * FROM user LIMIT 0,2; 从第0行开始查2个
使用mybatis实现分页,核心就是sql
接口
//分页查询
List<User> getUserByLimit(Map<String,Integer> map);
Mapper.xml
<!--分页-->
<select id="getUserByLimit" parameterType="map" resultMap="UserMap">
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> userList = mapper.getUserByLimit(map);
for (User user : userList) {
System.out.println(user);
}
sqlSession.close();
}
不再使用SQL实现分页
接口
//RowBounds分页查询
List<User> getUserByRowBounds();
Mapper.xml
<!--分页-->
<select id="getUserByRowBounds" resultMap="UserMap">
select * from mybatis.user
</select>
测试
@Test
public void testGetUserByRowBounds(){
SqlSession sqlSession = MybatisUtils.getSqlSession();
//RowBounds实现
RowBounds rowBounds = new RowBounds(0, 2);
//通过java代码层面实现分页
List<User> userList = sqlSession.selectList("com.lzt.dao.UserMapper.getUserByRowBounds",null,rowBounds);
sqlSession.close();
}
MyBatis 分页插件 PageHelper
大型复杂项目中使用,具体进官方文档中查看,有详细使用教程
标签:index ssi pre 处理 str help app select owb
原文地址:https://www.cnblogs.com/LiuOneZero/p/14467176.html