MyBatis返回resultType=Map时

 

mapper配置文件写法

 

36套java进阶高级架构师视频+38套大数据视频  保证全是硬货需要的
+微信:
du13797566440

<select id="statOnlineAndNotlineNumber" resultType="java.util.Map" parameterType="java.lang.String" >
  SELECT
online_state as state,
COUNT(online_state) as number
FROM
wl_rm_t_vehicle_state
<if test="operatorCode!=null and operatorCode!=''">
where operator_code LIKE CONCAT(#{operatorCode},'%')
</if>
GROUP BY
online_state
  </select>

 

其中列名 state、number对应key ,查出来的值对应value

mapper接口定义

List<Map<Integer,Integer>> statOnlineAndNotlineNumber(@Param("operatorCode") String operatorCode);

map应该装在list集合中,不然列名对应对个值时会报TooManyResultsException:

 

查出的结果如下:  [{number=11, state=1}, {number=6, state=2}]

 

 

 

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页