详解 AutoCode 插件的配置文件

本贴最后更新于 2142 天前,其中的信息可能已经渤澥桑田

一份全量的配置文件内容如下:

{
  "autoTypes": ["model","service","dao","mapper"],
  "project": {
    "path": "",
    "subModule": "autocode.test",
    "javaRoot": "src/main/java",
    "resourcesRoot": "src/main/resources",
    "testJavaRoot": "src/test/java/",
    "testResourcesRoot": "src/main/resources",
    "underline2Camel": true,
    "generateOgnl": false,
    "exclude": ["t_test_add_table"],
    "include": []
  },
  "model": {
    "summary": "",
    "packageName": "washmore.model",
    "visitorWithDoc": false,
    "toString": true
  },
  "dataFile": {
    "service": {
      "packageName": "washmore.service",
      "baseSuffix": "BaseService",
      "abstractBase": true,
      "batchLimit": 100,
      "suffix": "Service"
    },
    "dao": {
      "packageName": "washmore.dao",
      "baseSuffix": "BaseDao",
      "suffix": "Dao"
    },
    "mapper": {
      "fullParams": false,
      "usekeyProperty": true,
      "path": "mappers",
      "baseSuffix": "BaseMapper",
      "suffix": "Mapper"
    },
    "methodInclude": [],
    "methodExclude": []
  },
  "db": {
    "tableNamePrefix": ["t_","x_"],
    "driver": "com.mysql.jdbc.Driver",
    "url": "jdbc:mysql://localhost:3306/EmployeeCare",
    "username": "root",
    "password": ""
  },
  "doc": {
    "summary":"",
    "userGeneratorClass": "",
    "author": "Washmore",
    "version": "V1",
    "copyright": "(c) 2018, Washmore All Rights Reserved."
  },
  "dataType": {
    "date": ["timestamp","datetime"],
    "string": ["char","varchar","text"],
    "integer": ["int","smallint","tinyint"],
    "longL": ["bigint"],
    "doubleD": ["double","float"]
  }
}

autoTypes

配置需要生成的文件种类,目前支持的有 dao,service,mapper,model;

project 项目基础配置

path

指定文件生成的根目录,默认为当前项目跟目录

subModule

子模块名,适用于 maven 多 module 项目生成文件到指定子项目

javaRoot

即 maven 项目 build 节点的

    <sourceDirectory>.../src/main/java</sourceDirectory>

中的结尾内容,默认为 src/main/java

resourcesRoot,testJavaRoot,testResourcesRoot

参考 javaRoot 理解,略

underline2Camel

是否开启下划线转驼峰命名,默认 true

generateOgnl

暂未启用

include,exclude

表名列表,
如果 include 不为空,则生成 include 指定的表相关代码,
如果 include 为空的情况下 exclude 不为空,则生成排除掉 exclude 后剩下表的相关代码
如果都为空,则默认生成全部表相关代码

model

summary

生成的实体类类注释

packageName

生成的实体类包名

visitorWithDoc

是否生成 getter 方法注释,默认 false

toString

是否生成 toString 方法,默认 true

dataFile

methodInclude,methodExclude

方法名列表,目前支持的方法名包含

    selectByParams,
    countByParams,

    batchInsert,
    batchInsertSelective,
    batchUpdateByPrimaryKeySelective,
    batchDeleteByPrimaryKey,

    insert,
    insertSelective,
    updateByPrimaryKey,
    updateByPrimaryKeySelective,
    deleteByPrimaryKey,

    selectByPrimaryKey,
    selectByExample,
    countByExample;

配置项的意义参考 include,exclude 项

mapper

fullParams

是否生成全参数查询,默认 false
如果开启则生成的 selectByParams 方法包含所有字段作为条件,
如果不开启则生成的 selectByParams 方法仅包含主键(如果有的话)列作为条件,

usekeyProperty

是否在 insert 相关 xml 生成 keyProperty,用于插入操作为对象注入主键属性,默认 true

path

resourcesRoot 下的相对路径,默认 mappers

baseSuffix

生成的基础 mapper 后缀,默认 BaseMapper

suffix

生成的扩展 mapper 后缀,默认 Mapper

service

batchLimit

针对大数据量批量操作时设置分批,默认为空,如需要开启,推荐 100

abstractBase

暂未启用

其他参考 mapper,model

dao

参考 mapper,model,service

db

tableNamePrefix

表名前缀列表,默认为空,如配置,则生成的表相关代码中会移除前缀

driver,url,username,password

看着写吧

dataType

就用默认值不要改吧,瞎 j8 改也没啥大问题,仅影响生成的代码风格,自行摸索

doc

userGeneratorClass

用户自定义注释生成器类名,此类需继承自
tech.washmore.autocode.core.generator.base.JavaDocAbstractGenerator,
然后重写你想要自定义注释对应的方法

其他的用于生成类注释里面的东西,自行摸索

  • 代码
    459 引用 • 591 回帖 • 8 关注
  • Java

    Java 是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由 Sun Microsystems 公司于 1995 年 5 月推出的。Java 技术具有卓越的通用性、高效性、平台移植性和安全性。

    3168 引用 • 8207 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...