Skip to content

查询(query)

Mapper 内置方法

  • listAll():查询所有
  • listByIds(ID[]):根据ID条件,List查询
  • listByIds(Collection<ID>):根据ID条件,List查询
  • list(Where):动态条件,List查询

动态where查询

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;
    
    public void list() {
       List<SysUser> list= sysUserMapper.list(where->{
           where.like(SysUser::getUserName,"abc");
       });
    }
}

基于QueryChain(强大)

可构建复杂的场景, 更多操作前往 链路查询 - QueryChain

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;

    public void list() {
        List<SysUser> list= QueryChain.of(sysUserMapper)
                .like(SysUser::getUserName,"abc")
                .limit(10)
                .list();
    }
}