mybatis中如何使用limit实现分页功能.
mapper.xml
<select id="selectBylimit" resultType="com.shadow.foretaste.entity.UserInfo"> select * from user_info limit #{offset},#{pageSize} </select>
UserInfoMapper.java
/** * 查询指定数量 * @param offset * @param pageSize * @return */ List<UserInfo> selectBylimit(@Param("offset") int offset, @Param("pageSize") int pageSize);
测试文件:
@Test public void testSelectBylimit(){ SqlSession sqlSession = MyBatisUtils.getSession(); List<UserInfo> list = sqlSession.getMapper(UserInfoDao.class).selectBylimit(1, 3); System.out.println("-======="+list); }
时间: 2024-11-13 06:56:53