返回Map,Mybatis配置如下 :
ServiceImpl如下 :
public MapgetCountyHashMap(long id) { Map regionMap = regionInfoMapper.getCountyHashMap(id); Map resultMap = new HashMap (); String region = null; Long vid = null; for (Map.Entry entry : regionMap.entrySet()) { if ("NAME".equals(entry.getKey())) { region = (String) entry.getValue(); } else if ("ID".equals(entry.getKey())) { vid = ((java.math.BigDecimal) entry.getValue()).longValue(); } } resultMap.put(region, vid); return resultMap; }
Controller如下 :
@RequestMapping(value = "/region3", method = RequestMethod.GET) public @ResponseBody MapgetCountyMap(@RequestParam(required = true) int regionId) { return regionInfoService.getCountyHashMap(regionId); }
结果为 :
返回List<Map>类似 :
Mybatis配置 :
ServiceImpl如下 :
public MapgetRegionHashMap() { List
Controller如下 :
@RequestMapping(value = "/region2", method = RequestMethod.GET) public @ResponseBody MapgetRegionMap() { return regionInfoService.getRegionHashMap(); }
结果为 :