Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mysql-generator
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙长纪
mysql-generator
Commits
bf43cec6
Commit
bf43cec6
authored
Mar 29, 2019
by
孙长纪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加说明文件
parent
bcf3d4ad
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
fileHashes.bin
.gradle/4.6/fileHashes/fileHashes.bin
+0
-0
fileHashes.lock
.gradle/4.6/fileHashes/fileHashes.lock
+0
-0
README.md
README.md
+64
-1
No files found.
.gradle/4.6/fileHashes/fileHashes.bin
View file @
bf43cec6
No preview for this file type
.gradle/4.6/fileHashes/fileHashes.lock
View file @
bf43cec6
No preview for this file type
README.md
View file @
bf43cec6
# readme
# duiba根据数据库表自动生成代码
-
该工具根据数据库表名一键生成Entity、Dao、DaoImpl、mapper.xml文件,生成的文件直接存入当前工程指定的包下,目前只支持MySQL
-
实现上并没有集成MyBatis Generator,而是采用Freemarker生成代码,更加轻量,更容易定制SQL语句和命名风格
-
使用工具的价值在于减少人为工作量,统一代码风格
##使用方式
1.
首先根目录build.gradle文件中引入
```
dependency("cn.com.duiba:mysql-generator:0.0.1")
```
2.
在biz模块中引入
```
testCompile("cn.com.duiba:mysql-generator")
```
在test目录下新建CodeGeneratorTest.java,代码如下
```
java
public
class
MysqlGeneratorTest
{
private
static
final
String
DB_URL_TPL
=
"jdbc:mysql://dev.config.duibar.com:3306/{0}?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&connectTimeout=5000&socketTimeout=60000"
;
/**
* 库名
*/
private
static
final
String
TABLE_SCHEMA
=
"act_com_conf"
;
/**
* 表名
*/
private
static
final
String
TABLE_NAME
=
"tb_duiba_brick_config"
;
/**
* 数据库账户
*/
private
static
final
String
USER
=
"dev"
;
/**
* 数据库密码
*/
private
static
final
String
PWD
=
"dev_fas015"
;
@Test
public
void
createCode
(){
String
DB_URL
=
MessageFormat
.
format
(
DB_URL_TPL
,
TABLE_SCHEMA
);
GeneratorConfig
config
=
new
GeneratorConfig
(
DB_URL
,
USER
,
PWD
);
//生成dao代码位置
config
.
setDaoPackage
(
"cn.com.duiba.test.dao"
);
//生成entity代码位置
config
.
setEntityPackage
(
"cn.com.duiba.test.entity"
);
//mapper.xml文件位置
config
.
setXmlLocation
(
"src/main/resources/mybatis/test"
);
//数据库名
config
.
setTableSchema
(
TABLE_SCHEMA
);
//表名
config
.
setTableName
(
TABLE_NAME
);
//表前缀,设置该值后生成的Entity,dao,daoImpl类不会以tb开头
config
.
setTablePrefix
(
"tb"
);
//生成代码所在模块名称,可以不写
config
.
setModuleName
(
""
);
MybatisGenerator
.
genCode
(
config
);
}
}
```
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment