zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    react特点和创建虚拟DOM
    vue的keep-alive
    JavaScript-事件委托
    vue-router参数传递
    js常用的字符串处理
    vue-vuex
    vue-组件
    vue-父子组件传值
    堆和栈
    js-深拷贝浅拷贝
  • 原文地址:https://www.cnblogs.com/zhaopengcheng/p/6854265.html
Copyright © 2011-2022 走看看