关于java:18禁增删改查大法八荒篇

13次阅读

共计 2634 个字符,预计需要花费 7 分钟才能阅读完成。

@todo

  • JPA – 简短命名推理 @ugly
  • queryDSL – 黑化版 JPA @minor @ignore
  • MBG – 主动生成代码 @nice
  • MybatisPlus/tk – 无侵入加强 @nice
  • JOOQ – 链式正统 @nice @minor @pay @ignore
  • BeetlSQL – 去 XML 化 @minor @ignore
  • APIJSON – 反转业务控制权 @doubt @ignore
  • serverless – 灵便组装 @nice ->>

主动生成代码 @nice

  • MyBatisCodeHelperPro/EasyCode –> IDEA 插件 @nice
  • mybatis-generator @nice
  • mybatis-generator-gui

    • https://github.com/zouzg/myba…
  • auto-value

    • https://github.com/google/aut…
  • immutables

    • https://github.com/immutables…
  • hasor + Dataway ?? @todo

    • https://www.hasor.net/web/ind…
    • https://www.hasor.net/web/dat…
    • https://www.hasor.net/web/dat…

主动生成代码 @demo

  • easycode 应用 @simple

    • https://mp.weixin.qq.com/s/FE…
如同和 MyBatisCodeHelperPro 插件差不多

1) 装置 Easy Code 插件
2) 连贯数据库
2) 选中数据库表, 右键 EasyCode 生成

无侵入加强 @nice

  • mybatis-plus ->>
  • TKmybatis ->>
  • Ktorm

    • 基于 kotlin??
    • @code https://github.com/vincentlau…
    • @doc https://ktorm.liuwj.me/
// @demo 
val employees = Employees
    .joinReferencesAndSelect()
    .whereWithConditions {if (someCondition) {it += Employees.managerId.isNull()
        }
        if (otherCondition) {it += Employees.departmentId eq 1}
    }
    .orderBy(Employees.id.asc())
    .limit(0, 10)
    .map {Employees.createEntity(it) }

人道主义去 XML

  • beetlsql => markdown @minor
  • 间接写在 mybatis3 的注解里?? @ignore –> 放弃

人道主义去 XML @demo

  • Mybatis 去 xml 化 @building

    • kotlin 写的
    • https://juejin.im/post/5c139b…
    • @code https://github.com/wuhao000/m…
@SelectedProperties(properties=["id", "name", "age"])
fun findSimpleInfoList(): List<User>

反转业务控制权

艰深讲 就是甩锅给前端, 本人变成一个解决平台

  • APIJSON @ignore

    • 目前不太好用, 生态也不算成熟, 找不到后盾 demo, 算一种思路吧 @myself
    • 后端接口和文档自动化,前端(客户端) 定制返回 JSON 的数据和构造
    • @code

      • https://github.com/APIJSON/AP…
      • https://github.com/TommyLemon…
      • https://github.com/APIJSON/AP…
    • @doc

      • https://github.com/APIJSON/AP…
// 发送 JSON
{
  "Moment": {
    "id":12,
     "@column":"content"
  }
}

// 响应构造
{
    "Moment": {"content": "1111534034"},
    "code": 200,
    "msg": "success"
}

参考

  • Fluent MyBatis 应用入门 @todo

    • https://juejin.im/post/688479…
  • 这款工具让 SpringBoot 不再须要 Controller、Service、DAO、Mapper!@ad @ignore

    • https://mp.weixin.qq.com/s/pe…
  • SpringBoot 疾速整合 Mybatis(去 XML 化 + 注解进阶)@demo @ignore

    • @doc https://mp.weixin.qq.com/s/_O…
    • @code https://github.com/yizhiwazi/…
    • @doc-mybatis3 对应的文档 http://www.mybatis.org/mybati…
@Select
@Insert
@Update
@Delete

// 高级注解
@SelectProvider
@InsertProvider
@UpdateProvider
@DeleteProvider


@Results  用于填写后果集的多个字段的映射关系.
@Result  用于填写后果集的单个字段的映射关系.
@ResultMap 依据 ID 关联 XML 外面 <resultMap>.

// 疾速生成映射后果集
public static String getResultsStr(Class origin) {StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("@Results({\n");
    for (Field field : origin.getDeclaredFields()) {String property = field.getName();
        // 映射关系:对象属性(驼峰)-> 数据库字段(下划线)
        String column = new PropertyNamingStrategy.SnakeCaseStrategy().translate(field.getName()).toUpperCase();
        stringBuilder.append(String.format("@Result(property = \"%s\", column = \"%s\"),\n", property, column));
    }
    stringBuilder.append("})");
    return stringBuilder.toString();}
正文完
 0