nofaith
V2EX  ›  问与答

MyBatis 多表关联使用 ResultMap 嵌套好,还是是由 left join

  •  
  •   nofaith · Oct 5, 2020 · 1557 views
    This topic created in 2053 days ago, the information mentioned may be changed or developed.

    本人是新手小白,最近看了刘增辉写的《 MyBatis 从入门到精通》,里面提到通过 resultMap 这些属性实现嵌套映射,从最基本的 SQl 一层层嵌套,那在一对多的场景下,多表的情况下,是使用 left join 关联表好,还是书里面写的这种方法好?

    3 replies    2020-10-06 13:11:51 +08:00
    nofaith
        1
    nofaith  
    OP
       Oct 5, 2020
    有没有大佬了解?
    huijiewei
        2
    huijiewei  
       Oct 5, 2020   ❤️ 1
    resultMap 好。

    远离不必要的 JOIN
    taogen
        3
    taogen  
       Oct 6, 2020 via Android   ❤️ 1
    关联查询有联系实现方式:
    1. nested select
    2. nested resultmap

    官方建议使用 left join,即 nested resultmap 。这种方式一个 SQL 语句搞定。另一种则需要执行额外的查询语句。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5201 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 01:17 · PVG 09:17 · LAX 18:17 · JFK 21:17
    ♥ Do have faith in what you're doing.