mybatis返回一个map集合
程序员文章站
2022-06-30 20:48:08
...
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 ;
}
上一篇: Java学习自我总结——反射基础
下一篇: # Mybatis返回Map集合数据