Mybatis返回Map的key为实体的属性,value为实体

1、xml中这样写

	<resultMap id="BaseResultMap" type="com.entity.AirMonitor" >
        <result column="areaCode" property="areaCode"  />
        <result column="pm25" property="pm25" />
        <result column="pm10" property="pm10" />
    </resultMap>

    <select id="getDayMap" parameterType="java.util.Date" resultMap="BaseResultMap">
        SELECT 
            cast(avg(pm25) as decimal(18,2)) as pm25,
            cast(avg(pm10) as decimal(18,2)) as pm10
            area_code as areaCode
        FROM t_air_day_monitor day 
        WHERE monitor_time = date(#{date})
        GROUP BY point.area_code
    </select>

2、mapper中:

 	@MapKey("areaCode")
    Map<String,AirMonitorVo> getDayMap(Date date);

3、结果

Mybatis返回Map的key为实体的属性,value为实体_第1张图片

你可能感兴趣的:(Mybatis返回Map的key为实体的属性,value为实体)