// 指定功能键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);
}