# codemother-maven-plugin
**Repository Path**: osethan/codemother-maven-plugin
## Basic Information
- **Project Name**: codemother-maven-plugin
- **Description**: 辅助生成基础代码的maven插件
- **Primary Language**: Java
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-04-02
- **Last Updated**: 2021-06-11
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# README #
## What is this repository for? ##
通过简单配置,生成大量的基础代码,达到快速开发的目的。
支持数据库类型:MySql、Db2、PostgreSql、Oracle.
## How do I get set up? ##
### 创建模板文件夹 codemother ###
将本项目根目录中 codemother 目录复制到自己项目的根目录下。
template 下的模板可根据实际需要进行修改、新增和删除,模版语言是 freemarker,极易上手。
### 创建 schema 目录 ###
schema 目录用于存放业务表对应的 xml 配置文件(生成方法附在文档末),codemother 基于此配置文件以及模板生成代码。
在项目或模块中的 resources 目录下创建文件夹 com/ethanxx/codemother,其下包含 dbschema 文件夹以及 global.properties 文件,
dbschema 文件夹用于存放业务表对应的 xml 配置文件, global.properties 配置信息实例如下:
```
# 默认即可,无需更改
baseOutputPath=.
outputPathJava=src/main/java
outputPathJavaResource=src/main/resources
outputWebPath=src/main/webapp
outputPagePath=src/main/webapp/WEB-INF/page/
javaOutputPath=src/main/java
resourceOutputPath=src/main/resources
# 需要根据模块的包名修改
projectId=com.ethan.log
packagePath=com/ethan/log
modelPackage=com.ethan.log.model
mapperPackage=com.ethan.log.mapper
servicePackage=com.ethan.log.service
controllerPackage=com.ethan.log.ctl
controllerBasePackage=com.ethan.log.ctl.base
```
### 配置 maven 依赖 ###
在项目或者模块 pom.xml 中配置插件依赖:
```
com.ethanxx
codemother-maven-plugin
${codemother.version}
```
## How to run tests? ##
代码生成命令分两种情况:多模块项目结构、单体项目结构
### 多模块项目结构 ###
多模块项目代码生成步骤:
- 进入模块所在目录 `cd model1`
- 执行代码生成命令 `mvn codemother:code-generate`
多模块项目目录结构示例:
```
.
├── codemother
│ ├── codemother.properties
│ ├── dbschema
│ └── template
├── README.md
├── pom.xml
├── model1
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ └── java
└── model2
├── pom.xml
├── src
│ ├── main
│ │ ├── java
│ │ └── resources
│ └── test
└── java
```
### 单体项目结构 ###
单体结构项目代码生成命令需要指定 templatePath 参数。
进入项目根目录,执行命令:`mvn codemother:code-generate -DtemplatePath=./codemother/template`
> templatePath 参数默认值是 `../codemother/template`. 实际使用中应根据模板存放路径指定。
单模块项目目录结构示例:
```
.
├── codemother
│ ├── codemother.properties
│ ├── dbschema
│ └── template
├── pom.xml
└── src
├── main
│ ├── java
│ ├── resources
│ └── webapp
└── test
├── java
└── resources
```
## Schema 文件 ##
### 数据模型 Schema 文件生成方法 ###
插件提供了 SchemaGenerator 工具类,该工具类通过读取配置文件参数 codemother.properties,生成指定数据表的 schema 文件。
### 数据模型 Schema 文件说明 ###
数据模型 Schema 文件示例:
```
```
数据模型 Schema 文件的配置参数说明如下:
---
* 标签 key 描述了表的主键,包含属性 name,type,length 等; 当主键为序列时,添加 generator 属性,值为 native;
* 标签 match 表示查询时精确匹配;
* 标签 not-match 表示不匹配查询;
* 标签 match-value 表示查询时按特定的值进行查询;
* 标签 like 表示查询时模糊匹配;
* 标签 like-left 表示左模糊匹配;
* 标签 like-right 表示右模糊匹配;
* 标签 between 表示范围查询,low 和 high 分别表示查询范围的上下限;边界值是否包含取决于数据库类型(例如db2是左闭右开),如果边界值只传一个 low 或者 high,则按大于等于 low 或者小于等于 high 查询;
* 标签 in 表示包含查询(查询效率低,慎用),其参数值一个数组,如:"value1,value2,value3".split(",");
* 标签 not-in 表示不包含查询(查询效率低,慎用),其参数值一个数组,如:"value1,value2,value3".split(",");
* 标签 order-by 表示查询结果按该字段进行排序;
---
* 属性 column 指的表示 Table 的字段名;
* 属性 javaType 表示数据库字段类型对应在 Java 中的数据类型;缺省该属性则默认为 String;
* 属性 searchType 表示该字段在 Controller 接收页面传来的值的类型;缺省该属性则默认为 String;
* 属性 param 表示该字段在 Java 代码中的命名,以驼峰形式命名;缺省该属性则默认为 column 的值;
* 属性 asc 的值决定了查询结果的排序方式,false 表示按降序排列,缺省该属性或者设置为 true 表示按升序排列结果;
---