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
0b63df6f
Commit
0b63df6f
authored
Jun 06, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
插件重命名
parent
efc26b78
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
126 additions
and
11 deletions
+126
-11
src/main/java/com/itfsw/mybatis/generator/plugins/TablePrefixPlugin.java
...om/itfsw/mybatis/generator/plugins/TablePrefixPlugin.java
+104
-0
src/main/java/com/itfsw/mybatis/generator/plugins/TableSuffixPlugin.java
...om/itfsw/mybatis/generator/plugins/TableSuffixPlugin.java
+22
-11
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/TablePrefixPlugin.java
0 → 100644
View file @
0b63df6f
/*
* 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.utils.BasePlugin
;
import
org.mybatis.generator.api.IntrospectedTable
;
/**
* ---------------------------------------------------------------------------
* table前缀,解决多数据源表重名问题插件(为Model、Mapper、Example、xml等增加前缀)
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/5/18 13:54
* ---------------------------------------------------------------------------
*/
public
class
TablePrefixPlugin
extends
BasePlugin
{
public
static
final
String
PRE_PREFIX
=
"prefix"
;
// 前缀 property
private
String
prefix
;
// 前缀
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param introspectedTable
* @return
*/
@Override
public
void
initialized
(
IntrospectedTable
introspectedTable
)
{
// 1. 首先获取全局配置
this
.
prefix
=
getProperties
().
getProperty
(
PRE_PREFIX
);
// 2. 获取每个table 具体的
if
(
introspectedTable
.
getTableConfigurationProperty
(
PRE_PREFIX
)
!=
null
){
this
.
prefix
=
introspectedTable
.
getTableConfigurationProperty
(
PRE_PREFIX
);
}
// 3. 判断是否配置了前缀
if
(
this
.
prefix
!=
null
){
// 3.1. 为Model增加前缀
if
(
introspectedTable
.
getBaseRecordType
()
!=
null
){
introspectedTable
.
setBaseRecordType
(
this
.
renameJavaType
(
introspectedTable
.
getBaseRecordType
()));
}
// 3.2. 为ModelKey添加前缀
if
(
introspectedTable
.
getPrimaryKeyType
()
!=
null
){
introspectedTable
.
setPrimaryKeyType
(
this
.
renameJavaType
(
introspectedTable
.
getPrimaryKeyType
()));
}
// 3.3. WithBLOBs Model 添加前缀
if
(
introspectedTable
.
getRecordWithBLOBsType
()
!=
null
){
introspectedTable
.
setRecordWithBLOBsType
(
this
.
renameJavaType
(
introspectedTable
.
getRecordWithBLOBsType
()));
}
// 3.4. mapper 添加前缀
if
(
introspectedTable
.
getMyBatis3JavaMapperType
()
!=
null
){
introspectedTable
.
setMyBatis3JavaMapperType
(
this
.
renameJavaType
(
introspectedTable
.
getMyBatis3JavaMapperType
()));
}
// 3.5. example 添加前缀
if
(
introspectedTable
.
getExampleType
()
!=
null
){
introspectedTable
.
setExampleType
(
this
.
renameJavaType
(
introspectedTable
.
getExampleType
()));
}
// 3.6. Dao 添加前缀
if
(
introspectedTable
.
getDAOInterfaceType
()
!=
null
){
introspectedTable
.
setDAOInterfaceType
(
this
.
renameJavaType
(
introspectedTable
.
getDAOInterfaceType
()));
}
// 3.7. DAOImpl 添加前缀
if
(
introspectedTable
.
getDAOImplementationType
()
!=
null
){
introspectedTable
.
setDAOImplementationType
(
this
.
renameJavaType
(
introspectedTable
.
getDAOImplementationType
()));
}
// 3.8. 修正xml文件前缀
if
(
introspectedTable
.
getMyBatis3XmlMapperFileName
()
!=
null
){
introspectedTable
.
setMyBatis3XmlMapperFileName
(
this
.
prefix
+
introspectedTable
.
getMyBatis3XmlMapperFileName
());
}
}
}
/**
* 为类型添加前缀
*
* @param type
* @return
*/
private
String
renameJavaType
(
String
type
){
int
lastDot
=
type
.
lastIndexOf
(
"."
)
+
1
;
return
type
.
substring
(
0
,
lastDot
)
+
this
.
prefix
+
type
.
substring
(
lastDot
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/TableSuffixPlugin.java
View file @
0b63df6f
...
...
@@ -19,6 +19,8 @@ package com.itfsw.mybatis.generator.plugins;
import
com.itfsw.mybatis.generator.plugins.utils.BasePlugin
;
import
org.mybatis.generator.api.IntrospectedTable
;
import
java.util.List
;
/**
* ---------------------------------------------------------------------------
* table前缀,解决多数据源表重名问题插件(为Model、Mapper、Example、xml等增加前缀)
...
...
@@ -27,15 +29,25 @@ import org.mybatis.generator.api.IntrospectedTable;
* @time:2017/5/18 13:54
* ---------------------------------------------------------------------------
*/
@Deprecated
public
class
TableSuffixPlugin
extends
BasePlugin
{
public
static
final
String
PRE_SUFFIX
=
"suffix"
;
// 前缀 property
private
String
suffix
;
// 前缀
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
logger
.
warn
(
"itfsw:插件"
+
this
.
getClass
().
getTypeName
()
+
"插件已经过期,请使用TablePrefixPlugin插件替换(请原谅我蹩脚的英文水平)!"
);
return
super
.
validate
(
warnings
);
}
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param introspectedTable
* @return
*/
...
...
@@ -44,38 +56,38 @@ public class TableSuffixPlugin extends BasePlugin {
// 1. 首先获取全局配置
this
.
suffix
=
getProperties
().
getProperty
(
PRE_SUFFIX
);
// 2. 获取每个table 具体的
if
(
introspectedTable
.
getTableConfigurationProperty
(
PRE_SUFFIX
)
!=
null
){
if
(
introspectedTable
.
getTableConfigurationProperty
(
PRE_SUFFIX
)
!=
null
)
{
this
.
suffix
=
introspectedTable
.
getTableConfigurationProperty
(
PRE_SUFFIX
);
}
// 3. 判断是否配置了前缀
if
(
this
.
suffix
!=
null
){
if
(
this
.
suffix
!=
null
)
{
// 3.1. 为Model增加前缀
if
(
introspectedTable
.
getBaseRecordType
()
!=
null
){
if
(
introspectedTable
.
getBaseRecordType
()
!=
null
)
{
introspectedTable
.
setBaseRecordType
(
this
.
renameJavaType
(
introspectedTable
.
getBaseRecordType
()));
}
// 3.2. 为ModelKey添加前缀
if
(
introspectedTable
.
getPrimaryKeyType
()
!=
null
){
if
(
introspectedTable
.
getPrimaryKeyType
()
!=
null
)
{
introspectedTable
.
setPrimaryKeyType
(
this
.
renameJavaType
(
introspectedTable
.
getPrimaryKeyType
()));
}
// 3.3. WithBLOBs Model 添加前缀
if
(
introspectedTable
.
getRecordWithBLOBsType
()
!=
null
){
if
(
introspectedTable
.
getRecordWithBLOBsType
()
!=
null
)
{
introspectedTable
.
setRecordWithBLOBsType
(
this
.
renameJavaType
(
introspectedTable
.
getRecordWithBLOBsType
()));
}
// 3.4. mapper 添加前缀
if
(
introspectedTable
.
getMyBatis3JavaMapperType
()
!=
null
){
if
(
introspectedTable
.
getMyBatis3JavaMapperType
()
!=
null
)
{
introspectedTable
.
setMyBatis3JavaMapperType
(
this
.
renameJavaType
(
introspectedTable
.
getMyBatis3JavaMapperType
()));
}
// 3.5. example 添加前缀
if
(
introspectedTable
.
getExampleType
()
!=
null
){
if
(
introspectedTable
.
getExampleType
()
!=
null
)
{
introspectedTable
.
setExampleType
(
this
.
renameJavaType
(
introspectedTable
.
getExampleType
()));
}
// 3.6. 修正xml文件前缀
if
(
introspectedTable
.
getMyBatis3XmlMapperFileName
()
!=
null
){
if
(
introspectedTable
.
getMyBatis3XmlMapperFileName
()
!=
null
)
{
introspectedTable
.
setMyBatis3XmlMapperFileName
(
this
.
suffix
+
introspectedTable
.
getMyBatis3XmlMapperFileName
());
}
}
...
...
@@ -83,11 +95,10 @@ public class TableSuffixPlugin extends BasePlugin {
/**
* 为类型添加前缀
*
* @param type
* @return
*/
private
String
renameJavaType
(
String
type
){
private
String
renameJavaType
(
String
type
)
{
int
lastDot
=
type
.
lastIndexOf
(
"."
)
+
1
;
return
type
.
substring
(
0
,
lastDot
)
+
this
.
suffix
+
type
.
substring
(
lastDot
);
}
...
...
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