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()) + "");
}