mybatis中分页查询

1 如果在查询方法中有多个参数,可以使用map对象将所有数据都存储进去。比如分页查询,需要用到两个参数,可以将这两个参数包装到map中。

例子:分页查询

dao层方法

public List<Student> getStudentPage(int pstart, int pnumber) throws Exception{
SqlSession sqlSession = MybatisUtil.getSqlSession();
Map<String,Integer> map = new HashMap<String, Integer>();
map.put("pstart", pstart);
map.put("pnumber", pnumber); try{
return sqlSession.selectList(Student.class.getName() + ".getStudentPage", map);
}catch(Exception e){
e.printStackTrace();
throw new RuntimeException(e); }finally{
MybatisUtil.closeSqlSession();
}
}

映射文件studentmapper.xml

<select id="getStudentPage" parameterType="map" resultMap="studentMap">
select id,sname,salary
from student
limit #{pstart},#{pnumber} </select>
上一篇:angular ng-repeat radio取值


下一篇:BZOJ4571:[SCOI2016]美味(主席树,贪心)