项目实战 1.原始SQL
SELECT
bbb.symbol_id,
aaa.intepn,
aaa.componen_id,
ccc.supppn,
ddd.symbolinctimestamp
FROM
librarygraphic bbb
LEFT JOIN componen aaa ON bbb.componen_id = aaa.componen_id
LEFT JOIN supppart ccc ON aaa.componen_id = ccc.componen_id
LEFT JOIN logicsymbol ddd ON bbb.symbol_id = ddd.symbol_id
WHERE
bbb.symbol_id IS NOT NULL
AND aaa.intepn IS NOT NULL
AND ddd.symbolinctimestamp IS NOT NULL
AND aaa.grpname='Connector'
AND aaa.latest = 1
2.视图实体(封装查询结果)
@Data
public class LibrarygraphicBo {
private String symbolId;
private String intepn;
private String componenId;
private String supppn;
private String symbolinctimestamp;
}
3.Mybatis-Plus-Join
MPJLambdaWrapper<Librarygraphic> wrapper = new MPJLambdaWrapper<Librarygraphic>()
.selectAs(Librarygraphic::getSymbolId, LibrarygraphicBo::getSymbolId)
.selectAs(Componen::getIntepn, LibrarygraphicBo::getIntepn)
.selectAs(Componen::getComponenId, LibrarygraphicBo::getComponenId)
.selectAs(Supppart::getSupppn, LibrarygraphicBo::getSupppn)
.selectAs(Logicsymbol::getSymbolinctimestamp, LibrarygraphicBo::getSymbolinctimestamp)
.leftJoin(Componen.class, Componen::getComponenId, Librarygraphic::getComponenId)
.leftJoin(Supppart.class, Supppart::getComponenId, Componen::getComponenId)
.leftJoin(Logicsymbol.class, Logicsymbol::getSymbolId, Librarygraphic::getSymbolId)
.isNotNull(Librarygraphic::getSymbolId)
.isNotNull(Componen::getIntepn)
.isNotNull(Logicsymbol::getSymbolinctimestamp)
.eq(Componen::getGrpname, "Connector")
.eq(Componen::getLatest, 1);
List<LibrarygraphicBo> boList = librarygraphicMapper.selectJoinList(LibrarygraphicBo.class, wrapper);
注意:最终查询结果封装到了LibrarygraphicBo类型的集合