mybatis 返回 (List < Map < List > >)格式数据

需求:从数据库返回一对多数据
问题:通过查询得知,mybatis是无法直接返回此种格式的
解决方案:使用GROUP_CONCAT以json格式拼接字符串,返回json字符串,然后使用fastjson解析成list。

 SELECT
    w.user_id userId,
    w.data_time dataTime,
    u.user_name userName,
    concat('[',GROUP_CONCAT(concat('{"relId\":"',w.rel_id,'","proId":"',w.pro_id,'","proName":"',p.pro_name,'","parentProName":"',p1.pro_name,'","workTime":"',w.work_time,'","workRemark":"',w.work_remark,'","status":"',w.status
    ,'","updateTime":"',w.update_time,'"}')),']') workTimeListStr
    FROM
    pro_staff_work_time w left join pro_project_info p on p.pro_id = w.pro_id
    left join sys_user u on w.user_id  = u.clerk_id
    left join pro_project_info p1 on p.parent_id = p1.pro_id
     group by w.user_id,w.data_time
List<ProStaffWorkTime> list = proStaffWorkTimeService.findList(proStaffWorkTime);
        for (ProStaffWorkTime p: list) {
        //先用字符串接收,再解析成list
            List<ProStaffWorkTime> proProjectInfos = JSONObject.parseArray(p.getWorkTimeListStr(), ProStaffWorkTime.class);
            p.setWorkTimeList(proProjectInfos);
        }

你可能感兴趣的:(java)