mybatis()

---------------------------------mysql分页---------------------------------- 

public void selectList(int start,int size){
SqlSession sqlSession=null;
try{
sqlSession= MybatisUtil.getSqlSession();

Map map=new LinkedHashMap();

map.put("key1",start);

map.put("key2",size);

List<Students> students =sqlSession.selectList(Students.class.getName()+".selectList" ,map);
//mybatis必须手动提交事务,否则不会向数据库插入数据
for(Students student : students){
System.out.println(student);
}
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
}finally{
}

<select id="selectList" parameterType="map" resultType="student">
    select id,name,sal from students limit #{key1},#{key2}
</select>

--------------------------oracle分页----------------------

public List selectList(){
SqlSession sqlSession=null;
try{
Map map=new LinkedHashMap();
map.put("start", 4);
map.put("end", 7);
sqlSession= MybatisUtil.getSqlSession();
List<Students> student =sqlSession.selectList(Students.class.getName()+".selectListO", map);
//mybatis必须手动提交事务,否则不会向数据库插入数据
return student;
}catch(Exception e){
e.printStackTrace();
sqlSession.rollback();
throw new RuntimeException(e);
}finally{
MybatisUtil.closeSqlSession();
}
}

重要的是配置文件:

<!-- oracle分页代码 -->
<select id="selectListO" parameterType="map" resultType="student">
select *
from (select rownum num , students.* from students ) where num > #{start}
and num &lt; #{end}
</select>

posted @ 2016-05-10 19:03  李永  阅读(155)  评论(0编辑  收藏  举报