美文网首页
MyBatis List

MyBatis List

作者: 她是过来佛 | 来源:发表于2018-09-29 14:07 被阅读0次
    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()) + "");
        }
    

    相关文章

      网友评论

          本文标题:MyBatis List

          本文链接:https://www.haomeiwen.com/subject/zzmvoftx.html