mybatis 返回Map<String,List<Entity>> 格式数据
程序员文章站
2022-06-30 20:49:14
...
1、创建实体类
@Data
public class DisabilityManageVo1
{
private String disabilityManageId;
private List<DisabilityManageVo> list;
}
2、mapper
public List<DisabilityManageVo1> selectCompletionTime1(List<String> idList);
3、XML
<resultMap id="resultMap" type="com.hanclouds.system.domain.vo.DisabilityManageVo1">
<result column="id" property="disabilityManageId"/>
<collection property="list" ofType="com.hanclouds.system.domain.vo.DisabilityManageVo">
<result property="completionTime" column="completionTime"/>
<result property="nextServerTime" column="nextServerTime"/>
</collection>
</resultMap>
<select id="selectCompletionTime1" parameterType="list" resultMap="resultMap">
select
npt.completion_time as completionTime,
dm.id as id
from
nursing_personnel_task npt
inner join
plan_month pm on npt.rele_monthly_id = pm.id
inner join
disability_manage dm on pm.dis_id = dm.id
<where>
npt.task_states = '2'
and DATE(npt.completion_time) < DATE(NOW())
and
<foreach collection="list" item="id" separator="or" open="(" close=")">
dm.id = #{id}
</foreach>
</where>
ORDER BY npt.completion_time desc
</select>
4、转换成Map<String,List<Entity>> 格式
List<DisabilityManageVo1> disabilityManageVos = disabilityManageMapper.selectCompletionTime1(idList);
Map<String, List<DisabilityManageVo>> collect = disabilityManageVos.stream().collect(Collectors.toMap(DisabilityManageVo1::getDisabilityManageId, DisabilityManageVo1::getList));
优化查询,原来是多次查询数据库,现在是查询一次数据库返回所有数据;
上一篇: 关于verilog的一些基础知识整理
下一篇: ping命令执行过程详解
推荐阅读
-
mybatis 返回Map<String,List<Entity>> 格式数据
-
mybatis 返回 (List < Map < List > >)格式数据
-
mybatis 如何返回list
类型数据 -
mybatis 如何返回list
类型数据 -
Mybatis 如何 返回 List
类型 或 List -
Mybatis实现查询返回List《Map《String,Object》》格式数据(标题不让打尖括号)
-
mybatis 不依赖实体列名,使用List<Map<String,Object>>返回多条记录
-
mybatis 查询返回List<String>、Map<String,Object>、List<Map<String,Object>>