1.不使用聚合函數sql:
select * from sys_role_data a
left JOIN sys_office b ON a.office_id = b.id
LEFT JOIN sys_role c on a.role_id = c.id WHERE a.del_flag = '0'
如果沒有查出結果,則展示無記錄
2.使用 聚合函數, 我使用的是group_concat函數,來將結果部分元素聚合
SELECT
a.id AS "id",
a.kind AS "kind",
a.type AS "type",
a.role_id AS "roleId",
b.name AS "officeName",
c.name AS "roleName",
a.office_id AS "officeId",
group_concat(a.data_id) AS "dataId",
group_concat(a.data_name) AS "dataName",
a.useable AS "useable",
a.del_flag AS "delFlag",
a.remarks AS "remarks",
a.create_date AS "createDate",
a.create_by AS "createBy.id",
a.update_date AS "updateDate",
a.update_by AS "updateBy.id"
FROM sys_role_data a
LEFT JOIN
sys_office b
ON a.office_id = b.id
LEFT JOIN
sys_role c
ON a.role_id = c.id
WHERE a.del_flag = '0'
沒有查詢到結果,但是卻顯示第一條記錄,共一條,即出現瞭為Null的結果集。
應用在Mybatis中,返回結果為List時,會出現 List不為空,有一個元素為 all Elements are null.size為1,如果有做分頁處理,則也會有問題
出現這種情況,則需要對其返回集進行處理,過濾掉null元素,或者將null元素設置為相應的默認值
sysRoleData.setPage(page); List resultList = sysRoleDataDao.findList(sysRoleData); resultList.removeAll(Collections.singleton(null)); page.setList(resultList); page.setCount(resultList.size());
處理結果如上圖所示