MyBatis List<HashMap<String, Object>>

1.首先xml没有配置resultMap
    <select id="selectappointTms" parameterType="com.ccblife.cccp.co.business.pojo.req.QueryAppointmentListReq" resultType="java.util.HashMap">
        SELECT
          a1.POLICY_NO as contNo,
          COUNT(a1.POLICY_NO) as times
        FROM
              T_APPOINTMENT a1
        WHERE a1.POLICY_NO in
            (
                ......
            )
        GROUP BY
            a1.POLICY_NO
2.mapper.java中,map的value泛型为Object
    @Repository
    public interface TAppoinTmentMapper extends BaseMapper<TAppoinTment> {
        List<HashMap<String, Object>> selectappointTms (QueryAppointmentListReq req);
    }
3.在java类中,转换成map代码如
    List<HashMap<String, Object>> hashMapList = mapper.selectappointTms(req);
    HashMap<String, Object> resultMap = new HashMap<String, Object>();
    for (Map<String, Object> map : hashMapList) {
        String contNo = null;
        Integer times = null;
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            if ("CONTNO".equals(entry.getKey())) {
                contNo =  entry.getValue() + "";
            }else if ("TIMES".equals(entry.getKey())) {
                //没有配置resultMap,默认的数字类型是BigDecimal,不知直接用Integer强转
                times = ((java.math.BigDecimal) entry.getValue()).intValue();
            }
        }
        resultMap.put(contNo, times);
    }
    for(QueryAppointmentListResp resp : resps){
        resp.setAppointTms(resultMap.get(resp.getContNo()) + "");
    }
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容