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>
  • 相关阅读:
    leetcode
    leetcode
    leetcode
    leetcode
    Postman
    Fiddler抓百度和bing搜索包
    Jmeter脚本录制
    Android Studio使用Maven国内镜像
    Open Live Writer
    PureXXX使用手记
  • 原文地址:https://www.cnblogs.com/zhaopengcheng/p/6854265.html
Copyright © 2011-2022 走看看