mybatis中resulttype如下定义即可:
<!--查询订单状态表,返回一个map集合-->
<select id="selOrdersState" resultType="java.util.HashMap">
select state_id,state from order_state
</select>
mapper接口:
List<Map<Integer, String>> selOrdersState();
下面是将接收到的map进行处理:
@Override
public Map<Integer, String> selOrdersState() {
Map<Integer, String> stateMap = new HashMap<>();
List<Map<Integer, String>> mapList = orderMapper.selOrdersState();
for (Map<Integer, String> map: mapList) {
String state =null;
Integer state_id = null;
for (Map.Entry<Integer, String> maps:map.entrySet()) {
System.out.println("key"+maps.getKey());
//System.out.println("key"+maps.getValue());
if("state_id".equals(maps.getKey())){
state_id = new Integer(String.valueOf(maps.getValue()));
}
if("state".equals(maps.getKey())){
state = String.valueOf(maps.getValue());
}
stateMap.put(state_id,state);
}
}
return stateMap ;
}