<select id="listCategory" resultType="Category">
select * from category_
<if test="start!=null and count!=null">
limit #{start},#{count}
</if>
</select>
Test
Map<String,Object> params = new HashMap<>();
params.put("start", 0);
params.put("count", 5);
List<Category> cs =session.selectList("listCategory", params);
for (Category c : cs) {
System.out.println(c.getName());
}
插件方式
需要 pagehelper,jsqlparser
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor">
</plugin>
</plugins>
PageHelper.offsetPage(0, 5);
List<Category> cs =session.selectList("listCategory");
for (Category c : cs) {
System.out.println(c.getName());
}
// 获取总数顶
PageInfo pageInfo = new PageInfo<>(cs);
System.out.println("总数:"+pageInfo.getTotal());