Skip to content

联表查询

内联查询

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;

    public void page() {
        Pager<SysUser> pager= QueryChain.of(sysUserMapper)
                .select(SysUser.class)
                .from(SysUser.class)
                .join(SysUser.class,SysRole.class,on -> on.eq(SysUser::getRoleId, SysRole::getId))
                .like(SysUser::getUserName,"abc")
                .returnType(SysUser.class)
                .paging(Pager.of(1));
    }
}

左联查询

左联查询 适合1对1情况,如果不是,则分页时需要关闭框架优化:Pager.of(1).setOptimize(false)

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;

    public void page() {
        Pager<SysUser> pager= QueryChain.of(sysUserMapper)
                .select(SysUser.class)
                .from(SysUser.class)
                .join(JoinMode.LEFT, SysUser.class,SysRole.class,on -> on.eq(SysUser::getRoleId, SysRole::getId))
                .like(SysUser::getUserName,"abc")
                .returnType(SysUser.class)
                .paging(Pager.of(1));
    }
}

右联查询

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;

    public void page() {
        Pager<SysUser> pager= QueryChain.of(sysUserMapper)
                .select(SysUser.class)
                .from(SysUser.class)
                .join(JoinMode.RIGHT, SysUser.class,SysRole.class,on -> on.eq(SysUser::getRoleId, SysRole::getId))
                .like(SysUser::getUserName,"abc")
                .returnType(SysUser.class)
                .paging(Pager.of(1));
    }
}

全连接查询

java
public class Demo {
    @Autowired
    private SysUserMapper sysUserMapper;

    public void page() {
        Pager<SysUser> pager= QueryChain.of(sysUserMapper)
                .select(SysUser.class)
                .from(SysUser.class)
                .join(JoinMode.FULL, SysUser.class,SysRole.class,on -> on.eq(SysUser::getRoleId, SysRole::getId))
                .like(SysUser::getUserName,"abc")
                .returnType(SysUser.class)
                .paging(Pager.of(1));
    }
}