public List<Map<String, Object>> selectPublicItemList(@Param(value="sqlStr") String sqlStr);
2、mapper.xml
<select id="selectPublicItemList" parameterType="String" resultType="java.util.Map"> ${sqlStr} </select>
3、controller.java
@RequestMapping(value="/getPublicOptionItemList", method = RequestMethod.GET) @ResponseBody public Map<String, Object> getPublicOptionItemList(@RequestParam(required=true,value="sqlStr")String sqlStr) { try { FlowVariableMapper flowVariableMapper=(FlowVariableMapper)BeanFactory.getBean("flowVariableMapper"); List<Map<String, Object>> list=flowVariableMapper.selectPublicItemList(sqlStr); List<Map<String, Object>> ls=new ArrayList<>();//组装后的list if(null!=list&&list.size()>0){ //ObjectMapper mapper=new ObjectMapper(); //String jsonStr=mapper.writeValueAsString(list); //循环遍历2次,拿到第一个key和第二个key Map<String, Object> map=list.get(0); int i=0; String valueStr=""; String nameStr=""; for(java.util.Map.Entry<String, Object> entry : map.entrySet()) { if(i==0){ valueStr=entry.getKey(); } if(i==1){ nameStr=entry.getKey(); } ++i; } //根据拿到的key,重新进行组装 for (Map<String, Object> map2 : list) { Map<String, Object> newMap=new HashMap<>(); newMap.put("id", map2.get(valueStr)); newMap.put("itemName", map2.get(nameStr)); newMap.put("groupId", "public"); newMap.put("selected", false); ls.add(newMap);//添加 } } Map<String, Object> mapList=new HashMap<String, Object>(); mapList.put("list", ls); return mapList; } catch (Exception e) { LOGGER.error("Error method getPublicOptionItemList", e); throw new ActivitiException("Error method getPublicOptionItemList", e); } }