分頁查詢和分頁緩存查詢,List >遍歷和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());
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。