zoukankan      html  css  js  c++  java
  • mybatis 手写分页

    mybatis 手动分页查询 .xml文件

      SELECT
    ....
            FROM dip_pack_box AS t1
            LEFT JOIN dip_pack_content AS t2 ON t1.id = t2.superior_id AND t2.delete_flag = 0
            <where>
                t1.delete_flag = 0
                <if test= "null != name and '' != name">
                    <bind name="pattern_name" value="'%' + name +'%'"/>
                    AND t1.name like #{pattern_name}
                </if>
            </where>
              LIMIT #{index}, #{pageSize}
        </select>

    java文件 

    @Override
        public PageUtil pageSearch(Map<String,Object> param) {
            //第几页
            Integer current = (Integer) param.get("pageIndex");
            //每页大小
            Integer pageSize = (Integer) param.get("pageSize");
            int index = (current - 1) * pageSize;
            param.put("index",index);
            List<DipPackBoxEntity> boxEntityList = dipPackBoxDao.pageSearch(param);
            IPage<DipPackBoxEntity> iPage = new Page<>();
            iPage.setRecords(boxEntityList);
            return new PageUtil(iPage);
        }

    扩展性更好使用了<bind  name = "起个别名 比如pattern_name " value = " 指定产来的参数 比如 name ">  元素

     

    个人网址 http://threenut.cn/
  • 相关阅读:
    Reducing File Size
    程序设计中的命名
    代码进阶
    如何显示当前Mipmap级别?
    何时使用泛型集合
    Using Mono DLLs in a Unity Project
    lock关键字
    VSS/RSS/PSS/USS
    AssetBundle依赖
    WWW.LoadFromCacheOrDownload
  • 原文地址:https://www.cnblogs.com/july7/p/15357714.html
Copyright © 2011-2022 走看看