mapWithKey(query)
说明
把列表转成一个Map,KEY为指定字段的值
Mapper 内置方法
map(多个ID)
:多个ID,以ID为KEYmapWithKey(KEY字段,多个ID)
:多个IDmapWithKey(KEY字段,Where)
:动态条件
动态where查询
java
public class Demo {
@Autowired
private SysUserMapper sysUserMapper;
public void mapWithKey() {
Map<Integer,SysUser> map= sysUserMapper.mapWithKey(SysUser::getId,where->{
where.like(SysUser::getUserName,"abc");
});
}
}
基于QueryChain(强大)
可构建复杂的场景, 更多操作前往 链路查询 - QueryChain !
java
public class Demo {
@Autowired
private SysUserMapper sysUserMapper;
public void mapWithKey() {
Map<Integer,SysUser> map= QueryChain.of(sysUserMapper)
.like(SysUser::getUserName,"abc")
.limit(10)
.mapWithKey(SysUser::getId);
}
}