将后台数据取出放到页面的后台操作对比

//-------------------------------SELECT-----------------------------------------------------------------------
    // 指定功能键ID,返回与功能键名为键值对封装到列表中返回
    public String getFunctionKeys(int funcID){
        // 功能键列表结果变量
        Map<String, String> result = new HashMap<String, String>();
        
        // 获取功能键列表原始数据
        try{
            List<Map<String, Object>> funcList = funcKeyDao.getFunctionKeyList(funcID);
            // 包装功能键结果列表
            for(Map<String, Object> list : funcList){
                result.put(list.get("M_mstFunctionKey_id").toString(), list.get("FunctionName").toString());
            }
            
            return JSONUtil.serialize(result);
        }catch(JSONException ex){
            System.out.println("JSON data translation error.");
            return "";
        }catch(Exception ex){
            ex.printStackTrace();
            System.out.println("Get function key list error when call method getFunctionKeys.");
            return "";
        }        

    }

  for(Map<String, Object> list : funcList) 方法只使用与取两种数据,如果要取这张表中多个数据,怎需下列操作:

//-------------------------------SELECT-----------------------------------------------------------------------
    // 指定功能键ID,返回与功能键名为键值对封装到列表中返回
    public String getFunctionKeys(int funcID){
        // 功能键列表结果变量
        Map<String, Object> result =new HashMap<String, Object>();
        
        // 获取功能键列表原始数据
        
            List<Map<String, Object>> funcList = funcKeyDao.getFunctionKeyList(funcID);
            // 包装功能键结果列表
            if (funcList.size() > 0) {
                result.put("status", "0");
                List<String> Id = new ArrayList<String>();
                List<String> Name = new ArrayList<String>();
                List<String> Pic = new ArrayList<String>();
                for (int i = 0; i < funcList.size(); i++) {
                    Id.add(funcList.get(i).get("M_mstFunctionKey_id").toString());
                    Name.add(funcList.get(i).get("FunctionName").toString());
                    Pic.add(funcList.get(i).get("FunctionImageURL").toString());
                }
                result.put("M_mstFunctionKey_id", Id);
                result.put("FunctionName", Name);
                result.put("FunctionImageURL", Pic);
            
            } else {
                // 不存在数据
                result.put("status", "1");
                System.out.println("未放入");
            }
            String json = "";
            try{
                json =JSONUtil.serialize(result);
        }catch(JSONException ex){
            System.out.println("JSON data translation error.");
            return "";
        }catch(Exception ex){
            ex.printStackTrace();
            System.out.println("Get function key list error when call method getFunctionKeys.");
            return "";
        }    
            return json;
    }

// 选择全部功能键ID和名称
    public String getFunctionKeys(){
        return getFunctionKeys(0);
    }





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值