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

  • 相关阅读:
    c#: 传不确定个数参的方法
    导出Excel并设置样式
    无线网络国际会议排名
    初学Java接口
    初学Java修饰符
    [转]计算机类核心期刊投稿的一些资料汇总
    初学Java数据类型和变量
    初学Java数组
    初学Java运算符
    几个著名P2P会议与期刊及领军人物
  • 原文地址:https://www.cnblogs.com/ly-china/p/5479074.html
Copyright © 2020-2023  润新知