码迷,mamicode.com
首页 > 其他好文 > 详细

mybatis()

时间:2016-05-10 20:24:11      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:

---------------------------------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>

mybatis()

标签:

原文地址:http://www.cnblogs.com/ly-china/p/5479074.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!