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

@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();
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理