zoukankan      html  css  js  c++  java
  • 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询

    String sql = "返回所有符合条件记录的待分页SQL语句";
     int start = (page - 1) * limit + 1;
     int end = page * limit;
     sql = "select * from (select fulltable.*, ROWNUM RN from (" + sql + ") fulltable where ROWNUM <= " + end + ") where RN >= " + start;

    分页缓存查询

    private static List<Map<String, Object>> storageList;
        @PostConstruct//在需要自动启动的方法前加注释 @PostConstruct
        @Override
        public void refreshStorageMemory() {
            String sql = "select * from DM_STORAGE";
            storageList = dmJdbcTemplate.queryForList(sql);
        }
        @Override
        public List<Map<String, Object>> selectStorage(Integer page, Integer limit, Map<String, Object> operator) {
            if (page != null && limit != null && limit > 0) {
                int start = (page - 1) * limit;
                int end = page * limit;
                if (end > storageList.size()) {
                    end = storageList.size();
                }
                return storageList.subList(start, end);
            }
            else {
                return storageList;
            }
        }

    List<Map<,>>遍历取出Map

    Map<String, Object> matAuxPlanRec;
                for (int i = 0; i < matAuxPlanRecList.size(); i++) {
                    matAuxPlanRec = matAuxPlanRecList.get(i);
    }


    Map的get()方法获取key对应的value:String UNIT_ = (String) matAuxPlanRec.get("UNIT_");
    Map遍历:

    for (Map.Entry<String, Object> entry : matAuxPlanRec .entrySet()) {
                System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
    }
  • 相关阅读:
    sql中实现先排序后分组
    mysql中的锁机制之概念篇
    PHP对程序员的要求更高
    给初学PHP的学习线路和建议
    设计模式六大原则
    Mysql忘记密码怎么办
    数据库 sql
    精准优化 if…else ,干掉,过多,烂代码!
    JDK1.8 新特性(全)
    mysql 如何修改 删除 添加 表主键
  • 原文地址:https://www.cnblogs.com/shinelover/p/5930530.html
Copyright © 2011-2022 走看看