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
46793b36
Commit
46793b36
authored
Jun 09, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增注释插件
parent
cc043ac3
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
583 additions
and
5 deletions
+583
-5
src/main/java/com/itfsw/mybatis/generator/plugins/CommentPlugin.java
...va/com/itfsw/mybatis/generator/plugins/CommentPlugin.java
+42
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
...com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
+30
-5
src/main/java/com/itfsw/mybatis/generator/plugins/utils/PluginTools.java
...om/itfsw/mybatis/generator/plugins/utils/PluginTools.java
+15
-0
src/main/java/com/itfsw/mybatis/generator/plugins/utils/enhanced/TemplateCommentGenerator.java
...ator/plugins/utils/enhanced/TemplateCommentGenerator.java
+496
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/CommentPlugin.java
0 → 100644
View file @
46793b36
/*
* 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
java.util.Properties
;
/**
* ---------------------------------------------------------------------------
* 评论插件
* ---------------------------------------------------------------------------
* @author: hewei
* @time:2017/6/8 11:21
* ---------------------------------------------------------------------------
*/
public
class
CommentPlugin
extends
BasePlugin
{
public
static
final
String
PRE_TEMPLATE
=
"template"
;
// 模板 property
/**
* 插件具体实现查看BasePlugin
* @param properties
*/
@Override
public
void
setProperties
(
Properties
properties
)
{
super
.
setProperties
(
properties
);
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/BasePlugin.java
View file @
46793b36
...
@@ -16,14 +16,18 @@
...
@@ -16,14 +16,18 @@
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
package
com
.
itfsw
.
mybatis
.
generator
.
plugins
.
utils
;
import
com.itfsw.mybatis.generator.plugins.CommentPlugin
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.DefaultCommentGenerator
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.DefaultCommentGenerator
;
import
com.itfsw.mybatis.generator.plugins.utils.enhanced.TemplateCommentGenerator
;
import
org.mybatis.generator.api.CommentGenerator
;
import
org.mybatis.generator.api.CommentGenerator
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.api.PluginAdapter
;
import
org.mybatis.generator.config.Context
;
import
org.mybatis.generator.config.Context
;
import
org.mybatis.generator.config.PluginConfiguration
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.mybatis.generator.internal.util.StringUtility
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -49,13 +53,34 @@ public class BasePlugin extends PluginAdapter {
...
@@ -49,13 +53,34 @@ public class BasePlugin extends PluginAdapter {
super
.
setContext
(
context
);
super
.
setContext
(
context
);
// 配置插件使用的模板引擎
// 配置插件使用的模板引擎
if
(
context
.
getCommentGenerator
()
instanceof
org
.
mybatis
.
generator
.
internal
.
DefaultCommentGenerator
){
PluginConfiguration
cfg
=
PluginTools
.
getPluginConfiguration
(
CommentPlugin
.
class
,
context
);
if
(
cfg
==
null
||
cfg
.
getProperty
(
CommentPlugin
.
PRE_TEMPLATE
)
==
null
){
if
(
context
.
getCommentGeneratorConfiguration
().
getConfigurationType
().
equals
(
"DEFAULT"
)){
// 使用默认模板引擎
// 使用默认模板引擎
commentGenerator
=
new
DefaultCommentGenerator
();
commentGenerator
=
new
DefaultCommentGenerator
();
}
else
{
}
else
{
// 用户自定义
// 用户自定义
commentGenerator
=
context
.
getCommentGenerator
();
commentGenerator
=
context
.
getCommentGenerator
();
}
}
}
else
{
TemplateCommentGenerator
templateCommentGenerator
=
new
TemplateCommentGenerator
(
cfg
.
getProperty
(
CommentPlugin
.
PRE_TEMPLATE
));
// ITFSW 插件使用的注释生成器
commentGenerator
=
templateCommentGenerator
;
// 修正系统插件
try
{
// 先执行一次生成CommentGenerator操作,然后再替换
context
.
getCommentGenerator
();
Field
field
=
Context
.
class
.
getDeclaredField
(
"commentGenerator"
);
field
.
setAccessible
(
true
);
field
.
set
(
context
,
templateCommentGenerator
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"反射异常"
,
e
);
}
}
}
}
/**
/**
...
...
src/main/java/com/itfsw/mybatis/generator/plugins/utils/PluginTools.java
View file @
46793b36
...
@@ -81,4 +81,19 @@ public class PluginTools {
...
@@ -81,4 +81,19 @@ public class PluginTools {
}
}
return
new
ArrayList
<>();
return
new
ArrayList
<>();
}
}
/**
* 获取插件配置
*
* @param plugin 插件
* @param ctx 上下文
* @return
*/
public
static
PluginConfiguration
getPluginConfiguration
(
Class
plugin
,
Context
ctx
){
int
index
=
getPluginIndex
(
plugin
,
ctx
);
if
(
index
>
-
1
){
return
getConfigPlugins
(
ctx
).
get
(
index
);
}
return
null
;
}
}
}
src/main/java/com/itfsw/mybatis/generator/plugins/utils/enhanced/TemplateCommentGenerator.java
0 → 100644
View file @
46793b36
This diff is collapsed.
Click to expand it.
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