编辑:简单的说法,我想将动态列分组到pojo中的地图中。
我想使用ibatis来阅读pojos列表,但是pojo包含了我必须阅读的地图:
public class FundraiserSuccessData {
private String regionName;
private String fundraiserName;
// Key: Attendance ID, Value: Count
private Map<Integer, Integer> attendanceCount;
...
}
目前我将阅读出勤类型并将类型作为列表放入ibatis查询的参数中。
<select id="fundraiserSuccessReport.search" resultClass="controller.report.fundraiserSuccess.FundraiserSuccessData" parameterClass="controller.report.fundraiserSuccess.SearchRequest">
SELECT VALUE(MAX(r.name), 'D2D') regionName,
MAX(fr.firstname) || ' ' || MAX(fr.lastname) AS fundraiserName,
<iterate property="attendanceTypes" conjunction=","> MAX(attendance.$attendanceTypes[]$) $attendanceTypes[]$ </iterate>
...
JOIN (SELECT dps.person_id,
<iterate property="attendanceTypes" conjunction=",">
SUM(CASE WHEN attendance_id = $attendanceTypes[].id$ THEN 1 ELSE 0 END) $attendanceTypes[].name$
</iterate>
FROM daily_person_state dps
GROUP BY dps.person_id) attendance
ON fr.id = attendance.person_id
...
</select>
但是如何将联接映射到 attendanceCount ?因为我无法向java添加动态属性。