LongLights
V2EX  ›  Java

Mybatis 是注解方式用得多还是 xml 用得多

  •  
  •   LongLights · Mar 31, 2019 · 7750 views
    This topic created in 2777 days ago, the information mentioned may be changed or developed.

    最近在学习 ssm 框架的内容,单纯的比较好奇现在使用 Mybatis 是比较流行 xml 方式还是注解方式

    29 replies  •  2019-04-01 17:50:55 +08:00
    taaaang
    taaaang
    Mar 31, 2019
    1
    不知到你说的注解方式是用到什么程度,至少 sql 写注解里面是很操蛋的事情
    wolfie
    wolfie
    Mar 31, 2019
    2
    xml 吧,没见过用注解写动态 sql 的。
    cnbobolee
    cnbobolee
    Mar 31, 2019
    3
    注解吧,我以前的项目里面基本上看不到 xml 文件了。
    fumichael
    fumichael
    Mar 31, 2019
    4
    @taaaang #1 我见过别人的项目,简单的单表操作就是直接写注解,注解的内容就是 sql
    目前维护的都是统一写在 xml 里面
    LongLights
    LongLights
    OP
    Mar 31, 2019
    5
    看来还是得熟悉熟悉 xml 方式。。。现在好像比较喜欢写注解
    Salvation
    Salvation
    Mar 31, 2019❤️1
    6
    我目前遇到的都是 xml 用得多。

    各有利弊吧。
    glaucus
    glaucus
    Mar 31, 2019 via iPhone
    7
    简单注解,复杂 Provider
    sdxlh007
    sdxlh007
    Mar 31, 2019
    8
    我还是喜欢 xml 方式。。。但是公司很多人喜欢注解方式
    daimazha
    daimazha
    Mar 31, 2019
    9
    xml, 因为用 mbg 生成的
    taaaang
    taaaang
    Mar 31, 2019
    10
    @fumichael 简单 sql 写注解,就是写时一时爽,维护起来就会越来越操蛋。复杂 sql 就不用说了,直接 xml。如果表结构不负责,业务简单,那直接 JPA 得了.
    gejun123456
    gejun123456
    Mar 31, 2019
    11
    用 xml 可以试试 https://www.jianshu.com/p/1fb00955302a 使用 xml 效率很高
    buf1024
    buf1024
    Mar 31, 2019
    12
    xml 目前居多,但推荐注解方式,主流。
    jorneyr
    jorneyr
    Mar 31, 2019
    13
    推荐使用 xml
    wucao219101
    wucao219101
    Mar 31, 2019
    14
    MyBatis Generator 一键生成代码和 xml 避免大量手写
    mtus
    mtus
    Mar 31, 2019
    15
    还是 XML 方式更强大, 支持的扩展属性更多, 维护起来更方便.

    不过, 推荐看看 [jOOQ]( http://www.jooq.org/), 用起来更舒服.
    TommyLemon
    TommyLemon
    Apr 1, 2019
    16
    可以参考以前的 V2 帖子:现在用 mybatis 都不用 xml 了吗
    https://www.v2ex.com/t/541755
    kidlj
    kidlj
    Apr 1, 2019
    17
    @mtus Go 语言使用者看了看 jooq 的介绍有点儿眼红。哈哈哈哈。
    xuanbg
    xuanbg
    Apr 1, 2019
    18
    复杂 SQL 照样用注解!

    都 9102 年了,还用 XML 这种反人类的东西。。。
    jinghong
    jinghong
    Apr 1, 2019
    19
    xml
    lsongiu
    lsongiu
    Apr 1, 2019
    20
    xml
    qiyuey
    qiyuey
    Apr 1, 2019 via Android
    21
    注解
    AbnerYoo
    AbnerYoo
    Apr 1, 2019
    22
    用 xml,不过之前在 v2 看到有用 mybatis plus,感觉也挺不错的,有机会也尝试下
    gscoder
    gscoder
    Apr 1, 2019
    23
    复杂的用注解写很操蛋
    zorui
    zorui
    Apr 1, 2019
    24
    xml
    luosuosile
    luosuosile
    Apr 1, 2019
    25
    我自己都是写注解的,用个注解驱动,完全不用 xml 了。
    我觉得写在注解里面比在 xml 里面好读,还不用配置那么多。
    impossibleshen
    impossibleshen
    Apr 1, 2019
    26
    除去联合查询,单表的直接 orm 映射写 sql,像 mybatis-plus 等,但是 xml 有个好处就是用在多数据源可以通过 resource 来省去一部分配置,其他的都 9012 年了,还尼玛 xml
    VoidChen
    VoidChen
    Apr 1, 2019
    27
    我好像也就一年没写 web 怎么还倒退了?你们说的注解还是 ssh 那个时代的注解? xml 这个形式主要不是为了维护性吗,代码里面注解 sql 显得杂乱而且找起来也不方便吧。另外简单的增删查改不是用 spring 自带的 jpa 就好了吗。( ps:复杂 sql 最长的写过将近一页,跨库跨表多级嵌套= =)
    onice
    onice
    Apr 1, 2019
    28
    Mybatis 的 XML 就是为了解耦,把 SQL 从 Java 代码中抽离出来,让开发者专注于 SQL 实现。所以一般是 XML 用的多。
    codz
    codz
    Apr 1, 2019
    29
    XML 多.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1674 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 70ms · UTC 05:13 · PVG 13:13 · LAX 21:13 · JFK 00:13
    ♥ Do have faith in what you're doing.