Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mybatis-generator-plugin
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Administrator
mybatis-generator-plugin
Commits
9f7a4f55
Commit
9f7a4f55
authored
Jun 26, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ExampleTargetPlugin 插件测试用例
parent
ae31f59d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
252 additions
and
6 deletions
+252
-6
src/test/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPluginTest.java
...sw/mybatis/generator/plugins/ExampleTargetPluginTest.java
+91
-0
src/test/java/com/itfsw/mybatis/generator/plugins/tools/SqlHelper.java
.../com/itfsw/mybatis/generator/plugins/tools/SqlHelper.java
+1
-1
src/test/resources/db.properties
src/test/resources/db.properties
+20
-0
src/test/resources/mybatis-config.xml
src/test/resources/mybatis-config.xml
+6
-4
src/test/resources/scripts/ExampleTargetPlugin/init.sql
src/test/resources/scripts/ExampleTargetPlugin/init.sql
+26
-0
src/test/resources/scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml
.../ExampleTargetPlugin/mybatis-generator-without-plugin.xml
+51
-0
src/test/resources/scripts/ExampleTargetPlugin/mybatis-generator.xml
...sources/scripts/ExampleTargetPlugin/mybatis-generator.xml
+56
-0
src/test/resources/scripts/test_init.sql
src/test/resources/scripts/test_init.sql
+1
-1
No files found.
src/test/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPluginTest.java
0 → 100644
View file @
9f7a4f55
/*
* Copyright (c) 2017.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
;
import
com.itfsw.mybatis.generator.plugins.tools.DBHelper
;
import
org.apache.ibatis.io.Resources
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mybatis.generator.api.GeneratedJavaFile
;
import
org.mybatis.generator.api.MyBatisGenerator
;
import
org.mybatis.generator.config.Configuration
;
import
org.mybatis.generator.config.xml.ConfigurationParser
;
import
org.mybatis.generator.exception.InvalidConfigurationException
;
import
org.mybatis.generator.exception.XMLParserException
;
import
org.mybatis.generator.internal.DefaultShellCallback
;
import
java.io.IOException
;
import
java.sql.SQLException
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* ---------------------------------------------------------------------------
*
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/6/26 17:46
* ---------------------------------------------------------------------------
*/
public
class
ExampleTargetPluginTest
{
private
DBHelper
helper
;
/**
* 初始化
* @throws IOException
* @throws SQLException
*/
@Before
public
void
init
()
throws
IOException
,
SQLException
{
helper
=
DBHelper
.
getHelper
(
"scripts/ExampleTargetPlugin/init.sql"
);
}
@Test
public
void
testNormalPath
()
throws
IOException
,
XMLParserException
,
InvalidConfigurationException
,
SQLException
,
InterruptedException
{
List
<
String
>
warnings
=
new
ArrayList
<
String
>();
ConfigurationParser
cp
=
new
ConfigurationParser
(
warnings
);
Configuration
config
=
cp
.
parseConfiguration
(
Resources
.
getResourceAsStream
(
"scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml"
));
DefaultShellCallback
shellCallback
=
new
DefaultShellCallback
(
true
);
MyBatisGenerator
myBatisGenerator
=
new
MyBatisGenerator
(
config
,
shellCallback
,
warnings
);
myBatisGenerator
.
generate
(
null
,
null
,
null
,
false
);
List
<
GeneratedJavaFile
>
list
=
myBatisGenerator
.
getGeneratedJavaFiles
();
for
(
GeneratedJavaFile
file
:
list
){
if
(
file
.
getFileName
().
equals
(
"TbExample.java"
)){
Assert
.
assertEquals
(
file
.
getTargetPackage
(),
"com.itfsw.mybatis.generator.plugins.dao.model"
);
}
}
}
@Test
public
void
testConfigPath
()
throws
IOException
,
XMLParserException
,
InvalidConfigurationException
,
SQLException
,
InterruptedException
{
List
<
String
>
warnings
=
new
ArrayList
<
String
>();
ConfigurationParser
cp
=
new
ConfigurationParser
(
warnings
);
Configuration
config
=
cp
.
parseConfiguration
(
Resources
.
getResourceAsStream
(
"scripts/ExampleTargetPlugin/mybatis-generator.xml"
));
DefaultShellCallback
shellCallback
=
new
DefaultShellCallback
(
true
);
MyBatisGenerator
myBatisGenerator
=
new
MyBatisGenerator
(
config
,
shellCallback
,
warnings
);
myBatisGenerator
.
generate
(
null
,
null
,
null
,
false
);
List
<
GeneratedJavaFile
>
list
=
myBatisGenerator
.
getGeneratedJavaFiles
();
for
(
GeneratedJavaFile
file
:
list
){
if
(
file
.
getFileName
().
equals
(
"TbExample.java"
)){
Assert
.
assertEquals
(
file
.
getTargetPackage
(),
"com.itfsw.mybatis.generator.plugins.dao.example"
);
}
}
}
}
src/test/java/com/itfsw/mybatis/generator/plugins/tools/SqlHelper.java
View file @
9f7a4f55
...
@@ -41,7 +41,7 @@ import java.util.Map;
...
@@ -41,7 +41,7 @@ import java.util.Map;
/**
/**
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
*
*
From http://git.oschina.net/free/Mybatis_Utils/blob/master/SqlHelper/SqlHelper.java
* ---------------------------------------------------------------------------
* ---------------------------------------------------------------------------
* @author: hewei
* @author: hewei
* @time:2017/6/26 15:42
* @time:2017/6/26 15:42
...
...
src/test/resources/db.properties
0 → 100644
View file @
9f7a4f55
#
# Copyright (c) 2017.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
db.driver
=
com.mysql.jdbc.Driver
db.url
=
jdbc:mysql://localhost:3306/mybatis-generator-plugin?characterEncoding=UTF-8&allowMultiQueries=true
db.username
=
root
db.password
=
root
\ No newline at end of file
src/test/resources/mybatis-config.xml
View file @
9f7a4f55
...
@@ -17,15 +17,17 @@
...
@@ -17,15 +17,17 @@
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTDSQL Map Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTDSQL Map Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<configuration>
<properties
resource=
"db.properties"
/>
<!-- 配置环境,制定数据库连接信息 -->
<!-- 配置环境,制定数据库连接信息 -->
<environments
default=
"test"
>
<environments
default=
"test"
>
<environment
id=
"test"
>
<environment
id=
"test"
>
<transactionManager
type=
"JDBC"
/>
<transactionManager
type=
"JDBC"
/>
<dataSource
type=
"POOLED"
>
<dataSource
type=
"POOLED"
>
<property
name=
"driver"
value=
"
com.mysql.jdbc.Driver
"
/>
<property
name=
"driver"
value=
"
${db.driver}
"
/>
<property
name=
"url"
value=
"
jdbc:mysql://localhost:3306/mybatis-generator-plugin?characterEncoding=UTF-8&allowMultiQueries=true
"
/>
<property
name=
"url"
value=
"
${db.url}
"
/>
<property
name=
"username"
value=
"
root
"
/>
<property
name=
"username"
value=
"
${db.username}
"
/>
<property
name=
"password"
value=
"
root
"
/>
<property
name=
"password"
value=
"
${db.password}
"
/>
</dataSource>
</dataSource>
</environment>
</environment>
</environments>
</environments>
...
...
src/test/resources/scripts/ExampleTargetPlugin/init.sql
0 → 100644
View file @
9f7a4f55
/*
Navicat MySQL Data Transfer
Source Server : localhost
Source Server Version : 50617
Source Host : localhost:3306
Source Database : mybatis-generator-plugin
Target Server Type : MYSQL
Target Server Version : 50617
File Encoding : 65001
Date: 2017-06-26 17:30:13
*/
SET
FOREIGN_KEY_CHECKS
=
0
;
-- ----------------------------
-- Table structure for tb
-- ----------------------------
DROP
TABLE
IF
EXISTS
`tb`
;
CREATE
TABLE
`tb`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'注释1'
,
`field1`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'注释2'
,
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
;
\ No newline at end of file
src/test/resources/scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml
0 → 100644
View file @
9f7a4f55
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2017.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties
resource=
"db.properties"
/>
<!--导入属性配置 -->
<context
id=
"default"
targetRuntime=
"MyBatis3"
>
<!-- 插件 -->
<!--jdbc的数据库连接 -->
<jdbcConnection
driverClass=
"${db.driver}"
connectionURL=
"${db.url}"
userId=
"${db.username}"
password=
"${db.password}"
/>
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径 -->
<javaModelGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao.model"
targetProject=
"src/main/java"
>
<!-- 是否对model添加 构造函数 -->
<property
name=
"constructorBased"
value=
"true"
/>
<!-- 给Model添加一个父类 -->
<!--<property name="rootClass" value="com.itfsw.base"/>-->
</javaModelGenerator>
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<sqlMapGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao.mapping"
targetProject=
"src/main/java"
/>
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao"
targetProject=
"src/main/java"
type=
"XMLMAPPER"
/>
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table
tableName=
"tb"
>
<generatedKey
column=
"id"
sqlStatement=
"MySql"
identity=
"true"
/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
src/test/resources/scripts/ExampleTargetPlugin/mybatis-generator.xml
0 → 100644
View file @
9f7a4f55
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2017.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<!DOCTYPE generatorConfiguration
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
<properties
resource=
"db.properties"
/>
<!--导入属性配置 -->
<context
id=
"default"
targetRuntime=
"MyBatis3"
>
<!-- 插件 -->
<!-- Example 目标包修改插件 -->
<plugin
type=
"com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin"
>
<property
name=
"targetPackage"
value=
"com.itfsw.mybatis.generator.plugins.dao.example"
/>
</plugin>
<!--jdbc的数据库连接 -->
<jdbcConnection
driverClass=
"${db.driver}"
connectionURL=
"${db.url}"
userId=
"${db.username}"
password=
"${db.password}"
/>
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
targetPackage 指定生成的model生成所在的包名
targetProject 指定在该项目下所在的路径 -->
<javaModelGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao.model"
targetProject=
"src/main/java"
>
<!-- 是否对model添加 构造函数 -->
<property
name=
"constructorBased"
value=
"true"
/>
<!-- 给Model添加一个父类 -->
<!--<property name="rootClass" value="com.itfsw.base"/>-->
</javaModelGenerator>
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
<sqlMapGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao.mapping"
targetProject=
"src/main/java"
/>
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
<javaClientGenerator
targetPackage=
"com.itfsw.mybatis.generator.plugins.dao"
targetProject=
"src/main/java"
type=
"XMLMAPPER"
/>
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<table
tableName=
"tb"
>
<generatedKey
column=
"id"
sqlStatement=
"MySql"
identity=
"true"
/>
</table>
</context>
</generatorConfiguration>
\ No newline at end of file
src/test/resources/scripts/test_init.sql
View file @
9f7a4f55
...
@@ -23,7 +23,7 @@ CREATE TABLE `tb` (
...
@@ -23,7 +23,7 @@ CREATE TABLE `tb` (
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'注释1'
,
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'注释1'
,
`field1`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'注释2'
,
`field1`
varchar
(
255
)
DEFAULT
NULL
COMMENT
'注释2'
,
PRIMARY
KEY
(
`id`
)
PRIMARY
KEY
(
`id`
)
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
5
DEFAULT
CHARSET
=
latin1
;
);
-- ----------------------------
-- ----------------------------
-- Records of tb
-- Records of tb
...
...
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