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
3d0fa9b1
Commit
3d0fa9b1
authored
Apr 01, 2019
by
孙长纪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加详细描述
parent
b87ed3d8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
33 deletions
+48
-33
fileHashes.bin
.gradle/4.6/fileHashes/fileHashes.bin
+0
-0
fileHashes.lock
.gradle/4.6/fileHashes/fileHashes.lock
+0
-0
README.md
README.md
+22
-28
build.gradle
build.gradle
+1
-1
mysql-generator.iml
mysql-generator.iml
+1
-1
GeneratorConfig.java
.../cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
+13
-0
PathUtils.java
...in/java/cn/com/duiba/mysql/generator/utils/PathUtils.java
+11
-3
No files found.
.gradle/4.6/fileHashes/fileHashes.bin
View file @
3d0fa9b1
No preview for this file type
.gradle/4.6/fileHashes/fileHashes.lock
View file @
3d0fa9b1
No preview for this file type
README.md
View file @
3d0fa9b1
...
@@ -14,40 +14,34 @@ testCompile("cn.com.duiba:mysql-generator")
...
@@ -14,40 +14,34 @@ testCompile("cn.com.duiba:mysql-generator")
```
```
在test目录下新建CodeGeneratorTest.java,代码如下
在test目录下新建CodeGeneratorTest.java,代码如下
```
java
```
java
/**
* 根据数据库表生成代码
*/
public
class
MysqlGeneratorTest
{
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_SCHEMA
=
"act_com_conf"
;
//表名
/**
* 表名
*/
private
static
final
String
TABLE_NAME
=
"tb_duiba_brick_config"
;
private
static
final
String
TABLE_NAME
=
"tb_duiba_brick_config"
;
//生成entity代码位置
private
static
final
String
ENTITY_PACKAGE
=
"cn.com.duiba.activity.center.biz.test.entity"
;
//生成dao代码位置
private
static
final
String
DAO_PACKAGE
=
"cn.com.duiba.activity.center.biz.test.dao"
;
//mapper.xml文件位置,需要加上所在的模块名称下位置,比如activity-center-deploy模块下src/main/resources/mybatis/test目录下
private
static
final
String
XML_LOCATION
=
"activity-center-deploy/src/main/resources/mybatis/test"
;
/**
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
USER
=
"dev"
;
/**
* 数据库密码
*/
private
static
final
String
PWD
=
"dev_fas015"
;
@Test
@Test
public
void
createCode
(){
public
void
generateCode
(){
String
DB_URL
=
MessageFormat
.
format
(
DB_URL_TPL
,
TABLE_SCHEMA
);
String
DB_URL
=
MessageFormat
.
format
(
DB_URL_TPL
,
TABLE_SCHEMA
);
GeneratorConfig
config
=
new
GeneratorConfig
(
DB_URL
,
USER
,
PWD
);
GeneratorConfig
config
=
new
GeneratorConfig
(
DB_URL
,
"dev"
,
"dev_fas015"
);
//生成dao代码位置
config
.
setDaoPackage
(
"cn.com.duiba.test.dao"
);
//生成entity代码位置
//生成entity代码位置
config
.
setEntityPackage
(
"cn.com.duiba.test.entity"
);
config
.
setEntityPackage
(
ENTITY_PACKAGE
);
//mapper.xml文件位置
config
.
setTestExe
(
false
);
config
.
setXmlLocation
(
"src/main/resources/mybatis/test"
);
//生成dao代码位置
config
.
setDaoPackage
(
DAO_PACKAGE
);
//mapper.xml文件位置,以测试用例的方式启动则
config
.
setXmlLocation
(
XML_LOCATION
);
//数据库名
//数据库名
config
.
setTableSchema
(
TABLE_SCHEMA
);
config
.
setTableSchema
(
TABLE_SCHEMA
);
//表名
//表名
...
@@ -57,7 +51,7 @@ public class MysqlGeneratorTest {
...
@@ -57,7 +51,7 @@ public class MysqlGeneratorTest {
//设置生成的java文件存放的模块名,如果该代码执行和生成的代码在一个模块下则不需要设置,
//设置生成的java文件存放的模块名,如果该代码执行和生成的代码在一个模块下则不需要设置,
//比如该执行代码在activity-center-deploy模块下,需要生成的entity,dao,daoImpl需要在activity-center-biz模块下,则需要设置ModuleName的值为activity-center-biz
//比如该执行代码在activity-center-deploy模块下,需要生成的entity,dao,daoImpl需要在activity-center-biz模块下,则需要设置ModuleName的值为activity-center-biz
//如果该执行代码在activity-center-biz下,并且生成的代码也在activity-center-biz下则不需要设置ModuleName的值
//如果该执行代码在activity-center-biz下,并且生成的代码也在activity-center-biz下则不需要设置ModuleName的值
config
.
setModuleName
(
""
);
config
.
setModuleName
(
"
activity-center-biz
"
);
MybatisGenerator
.
genCode
(
config
);
MybatisGenerator
.
genCode
(
config
);
}
}
...
...
build.gradle
View file @
3d0fa9b1
...
@@ -18,7 +18,7 @@ apply plugin: "idea"
...
@@ -18,7 +18,7 @@ apply plugin: "idea"
apply
plugin:
"eclipse"
apply
plugin:
"eclipse"
group
=
"cn.com.duiba"
group
=
"cn.com.duiba"
version
=
"0.1.
0
"
version
=
"0.1.
1
"
sourceCompatibility
=
1.8
sourceCompatibility
=
1.8
targetCompatibility
=
1.8
targetCompatibility
=
1.8
...
...
mysql-generator.iml
View file @
3d0fa9b1
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<module
external.linked.project.id=
"mysql-generator"
external.linked.project.path=
"$MODULE_DIR$"
external.root.project.path=
"$MODULE_DIR$"
external.system.id=
"GRADLE"
external.system.module.group=
"cn.com.duiba"
external.system.module.version=
"0.
0.1
"
type=
"JAVA_MODULE"
version=
"4"
>
<module
external.linked.project.id=
"mysql-generator"
external.linked.project.path=
"$MODULE_DIR$"
external.root.project.path=
"$MODULE_DIR$"
external.system.id=
"GRADLE"
external.system.module.group=
"cn.com.duiba"
external.system.module.version=
"0.
1.0
"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<component
name=
"NewModuleRootManager"
inherit-compiler-output=
"true"
>
<exclude-output
/>
<exclude-output
/>
<content
url=
"file://$MODULE_DIR$"
>
<content
url=
"file://$MODULE_DIR$"
>
...
...
src/main/java/cn/com/duiba/mysql/generator/entity/GeneratorConfig.java
View file @
3d0fa9b1
...
@@ -51,6 +51,11 @@ public class GeneratorConfig {
...
@@ -51,6 +51,11 @@ public class GeneratorConfig {
*/
*/
private
String
moduleName
;
private
String
moduleName
;
/**
* true:以测试用例执行生成代码的方式
*/
private
boolean
exeTest
=
false
;
public
GeneratorConfig
(
String
dbUrl
,
String
dbUserName
,
String
dbPasswd
)
{
public
GeneratorConfig
(
String
dbUrl
,
String
dbUserName
,
String
dbPasswd
)
{
this
.
connection
=
MybatisGenerator
.
getConnection
(
dbUrl
,
dbUserName
,
dbPasswd
);
this
.
connection
=
MybatisGenerator
.
getConnection
(
dbUrl
,
dbUserName
,
dbPasswd
);
}
}
...
@@ -136,4 +141,12 @@ public class GeneratorConfig {
...
@@ -136,4 +141,12 @@ public class GeneratorConfig {
public
void
setModuleName
(
String
moduleName
)
{
public
void
setModuleName
(
String
moduleName
)
{
this
.
moduleName
=
moduleName
;
this
.
moduleName
=
moduleName
;
}
}
public
boolean
isExeTest
()
{
return
exeTest
;
}
public
void
setExeTest
(
boolean
exeTest
)
{
this
.
exeTest
=
exeTest
;
}
}
}
src/main/java/cn/com/duiba/mysql/generator/utils/PathUtils.java
View file @
3d0fa9b1
...
@@ -28,8 +28,16 @@ public class PathUtils {
...
@@ -28,8 +28,16 @@ public class PathUtils {
if
(
StringUtils
.
isEmpty
(
config
.
getModuleName
()))
{
if
(
StringUtils
.
isEmpty
(
config
.
getModuleName
()))
{
return
"src/main/java/"
+
StringUtils
.
replace
(
packageName
,
"."
,
"/"
);
return
"src/main/java/"
+
StringUtils
.
replace
(
packageName
,
"."
,
"/"
);
}
}
String
modulePath
=
getProjectHome
();
String
filePath
=
config
.
getModuleName
()
+
File
.
separator
+
"src/main/java/"
+
StringUtils
.
replace
(
packageName
,
"."
,
"/"
);
String
bathPath
=
modulePath
.
substring
(
0
,
modulePath
.
lastIndexOf
(
File
.
separator
));
//以main方法执行
return
bathPath
+
File
.
separator
+
config
.
getModuleName
()
+
File
.
separator
+
"src/main/java/"
+
StringUtils
.
replace
(
packageName
,
"."
,
"/"
);
if
(
config
.
isExeTest
())
{
//以测试用例的方式执行
String
modulePath
=
getProjectHome
();
String
bathPath
=
modulePath
.
substring
(
0
,
modulePath
.
lastIndexOf
(
File
.
separator
));
return
bathPath
+
File
.
separator
+
filePath
;
}
return
filePath
;
}
}
}
}
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