首页 > 其他 > 详细

mybatis()

时间:2016-05-10 20:23:53      阅读:134      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!