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
ed19ffa9
Commit
ed19ffa9
authored
Jan 12, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Example 目标包修改插件
parent
b564e9d9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
91 additions
and
0 deletions
+91
-0
README.md
README.md
+11
-0
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
.../itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
+80
-0
No files found.
README.md
View file @
ed19ffa9
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
*
MySQL分页插件
*
MySQL分页插件
*
数据Model链式构建插件
*
数据Model链式构建插件
*
Example Criteria 增强插件
*
Example Criteria 增强插件
*
Example 目标包修改插件
---------------------------------------
---------------------------------------
Maven引用:
Maven引用:
...
@@ -159,4 +160,14 @@ public class Test {
...
@@ -159,4 +160,14 @@ public class Test {
.
example
();
.
example
();
}
}
}
}
```
### 5. Example 目标包修改插件
Mybatis Generator 插件默认把Model类和Example类都生成到一个包下,这样该包下类就会很多不方便区分,该插件目的就是把Example类独立到一个新包下,方便查看。
插件:
```
xml
<!-- Example 目标包修改插件 -->
<plugin
type=
"com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin"
>
<!-- 修改Example类生成到目标包下 -->
<property
name=
"targetPackage"
value=
"com.itfsw.mybatis.generator.dao.example"
/>
</plugin>
```
```
\ No newline at end of file
src/main/java/com/itfsw/mybatis/generator/plugins/ExampleTargetPlugin.java
0 → 100644
View file @
ed19ffa9
/*
*
* * Copyright (c) 2014.
* *
* * 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
org.mybatis.generator.api.IntrospectedTable
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.config.Context
;
import
org.mybatis.generator.config.JavaModelGeneratorConfiguration
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.util.List
;
import
java.util.Properties
;
/**
* ---------------------------------------------------------------------------
* Example类生成位置修改
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/1/12 12:36
* ---------------------------------------------------------------------------
*/
public
class
ExampleTargetPlugin
extends
PluginAdapter
{
public
static
final
String
TARGET_PACKAGE_KEY
=
"targetPackage"
;
// 配置targetPackage名
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CriteriaBuilderPlugin
.
class
);
private
String
targetPackage
;
// 目标包
/**
* {@inheritDoc}
*/
@Override
public
boolean
validate
(
List
<
String
>
warnings
)
{
// 获取配置的目标package
Properties
properties
=
getProperties
();
this
.
targetPackage
=
properties
.
getProperty
(
TARGET_PACKAGE_KEY
);
if
(
this
.
targetPackage
==
null
){
logger
.
warn
(
"请配置com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin插件的目标包名(targetPackage)!"
);
return
false
;
}
return
true
;
}
/**
* 初始化阶段
* 具体执行顺序 http://www.mybatis.org/generator/reference/pluggingIn.html
*
* @param introspectedTable
*/
@Override
public
void
initialized
(
IntrospectedTable
introspectedTable
)
{
String
exampleType
=
introspectedTable
.
getExampleType
();
// 修改包名
Context
context
=
getContext
();
JavaModelGeneratorConfiguration
configuration
=
context
.
getJavaModelGeneratorConfiguration
();
String
targetPackage
=
configuration
.
getTargetPackage
();
String
newExampleType
=
exampleType
.
replace
(
targetPackage
,
this
.
targetPackage
);
introspectedTable
.
setExampleType
(
newExampleType
);
logger
.
debug
(
"itfsw:修改"
+
exampleType
+
"的包到"
+
this
.
targetPackage
);
}
}
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