一、Limit分页使用:
1、编写接口:
分页查询
List getUserBylimit(Map<String,Integer>map);
2、编写mapper.xml 文件
<resultMap id="UserMap" type="User">
<result column="pwd" property="password"/>
</resultMap>
<!--分页查询 -->
<select id="getUserBylimit" resultType="map" resultMap="UserMap">
select * from user limit #{startIndex},#{pagSize}
</select>
3、测试跑程序编写
@Test
public void test2(){
SqlSession sqlSession = MybatisUtils.getSQLSession();
UserMapper mapper = sqlSession.getMapper(UserMapper.class);
HashMap<String, Integer> map = new HashMap<String, Integer>();
map.put(“startIndex”,0);
map.put(“pagSize”,2);
List userList = mapper.getUserBylimit(map);
for (User user:userList){
System.out.println(user);
}
sqlSession.close();
}
二、报错信息:
Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; 不允许有匹配 “[xX][mM][lL]” 的处理指令目标。
解决办法:
查看xml文件内开头是否有空格,我的正是此问题导致。
MyBatis 分页插件 PageHelper
网址:
https://pagehelper.github.io/docs/howtouse/