博主首页

Mybatis-plus-join使用、mybatis连表

public interface PlanDayMapper  extends MPJBaseMapper<PwPlanDayPO> {
}
        MPJLambdaWrapper<PwPlanDayPO> wrapper = MPJWrappers.lambdaJoin(PwPlanDayPO.class);
        wrapper.leftJoin(SysStaffPO.class,SysStaffPO::getStaffId,PwPlanDayPO::getLeadCode)
                .eq(PwPlanDayPO::getId,"14026b06-d626-4099-adfe-91679f41cac2")
                .select(PwPlanDayPO::getCode)
                .selectAs(SysStaffPO::getStaffId,PwPlanDayPO::getLeadCode);
        List<TSscPlanDayDto> dayDtos = planDayMapper.selectJoinList(TSscPlanDayDto.class, wrapper);
 SysOrganPOService extends MPJBaseServiceImpl<SysOrganMapper,SysOrganPO> {

 

 

生成的sql

SELECT t.`code`,t1.`STAFF_ID` AS leadCode FROM PW_PLAN_DAY t LEFT JOIN SYS_STAFF t1 ON (t1.`STAFF_ID` = t.`lead_code`) WHERE (t.`id` = '14026b06-d626-4099-adfe-91679f41cac2')
                 

引入依赖

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.3.4</version>
        </dependency>

        <dependency>
            <groupId>com.github.yulichang</groupId>
            <artifactId>mybatis-plus-join-boot-starter</artifactId>
            <version>1.4.6</version>
        </dependency>

 

likeRight   以什么开头

 

连表多条件案例

      MPJLambdaWrapper<PwPlanDayPO> select = MPJWrappers.lambdaJoin(PwPlanDayPO.class)
                .leftJoin(PwPlanDayExecutePO.class, PwPlanDayExecutePO::getObjPlan, PwPlanDayPO::getId)
                .leftJoin(PwEngBasePO.class, PwEngBasePO::getEngId, PwPlanDayPO::getEngId)
                .leftJoin(PwPlanDayPositionPO.class, PwPlanDayPositionPO::getObjDayplan, PwPlanDayPO::getId)
                .leftJoin(PwFileInfoTablePO.class, PwFileInfoTablePO::getRelateBussTableId, PwPlanDayPO::getId)
                .leftJoin(PwPlanOperateLogPO.class, PwPlanOperateLogPO::getObjPlan, PwPlanDayPO::getId)
                .leftJoin(TSscPlanDayChkPO.class, TSscPlanDayChkPO::getObjDayplan, PwPlanDayPO::getId)
                .leftJoin(WorkPointPO.class, WorkPointPO::getTaskCode, PwPlanDayPO::getCode)
                .leftJoin(SysStaffPO.class, on -> on.eq(SysStaffPO::getStaffId, PwPlanDayPositionPO::getPersonCode)
                        .or().eq(SysStaffPO::getStaffId, PwPlanDayPO::getLeadCode))
                .selectAll(PwPlanDayPO.class)

 排除字段案例

        LambdaQueryWrapper<PwPlanDayPositionPO> queryWrapper =
                Wrappers.lambdaQuery(PwPlanDayPositionPO.class)
                .eq(PwPlanDayPositionPO::getObjDayplan, objDayplan)
                .and(and -> and.ne(PwPlanDayPositionPO::getIsDelete, "1").or().isNull(PwPlanDayPositionPO::getIsDelete))
                .orderByAsc(PwPlanDayPositionPO::getCreateTime)
                        .select(PwPlanDayPositionPO.class,i->!i.getColumn().equals("id_card"));

 

posted @ 2023-09-04 11:49  笑~笑  阅读(936)  评论(0编辑  收藏  举报