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
e908f149
Commit
e908f149
authored
Jul 03, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新插件描述文档
parent
51b812a5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
1 deletion
+64
-1
README.md
README.md
+64
-1
No files found.
README.md
View file @
e908f149
...
...
@@ -17,6 +17,8 @@
*
[
Table增加前缀插件(TablePrefixPlugin)
](
#11-table增加前缀插件
)
*
[
Table重命名插件(TableRenamePlugin)
](
#12-table重命名插件
)
*
[
自定义注释插件(CommentPlugin)
](
#13-自定义注释插件
)
*
[
增量插件(IncrementsPlugin)
](
#14-增量插件
)
*
[
查询结果选择性返回插件(SelectSelectivePlugin)
](
#15-查询结果选择性返回插件
)
---------------------------------------
Maven引用:
...
...
@@ -981,3 +983,64 @@ Mybatis Generator是原生支持自定义注释的(commentGenerator配置type
]]>
</comment>
</template>
```
### 13. 增量插件
为更新操作生成set filedxxx = filedxxx +/- inc 操作,方便某些统计字段的更新操作,常用于某些需要计数的场景;
插件:
```
xml
<xml>
<!-- 增量插件 -->
<plugin
type=
"com.itfsw.mybatis.generator.plugins.IncrementsPlugin"
/>
<table
tableName=
"tb"
>
<!-- 配置需要进行增量操作的列名称(英文半角逗号分隔) -->
<property
name=
"incrementsColumns"
value=
"field1,field2"
/>
</table>
</xml>
```
使用:
```
java
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
// 在构建更新对象时,配置了增量支持的字段会增加传入增量枚举的方法
Tb
tb
=
new
Tb
.
Builder
()
.
id
(
102
)
.
field1
(
1
,
Tb
.
Builder
.
Inc
.
INC
)
// 字段1 统计增加1
.
field2
(
2
,
Tb
.
Builder
.
Inc
.
DEC
)
// 字段2 统计减去2
.
field4
(
new
Date
())
.
build
();
// 更新操作,可以是 updateByExample, updateByExampleSelective, updateByPrimaryKey
// , updateByPrimaryKeySelective, upsert, upsertSelective等所有涉及更新的操作
this
.
tbMapper
.
updateByPrimaryKey
(
tb
);
}
}
```
### 13. 查询结果选择性返回插件
一般我们在做查询优化的时候会要求查询返回时不要返回自己不需要的字段数据,因为Sending data所花费的时间和加大内存的占用
,所以我们看到官方对于大数据的字段会拆分成xxxWithBLOBs的操作,但是这种拆分还是不能精确到具体列返回。
所以该插件的作用就是精确指定查询操作所需要返回的字段信息,实现查询的精确返回。
插件:
```
xml
<xml>
<!-- 查询结果选择性返回插件 -->
<plugin
type=
"com.itfsw.mybatis.generator.plugins.SelectSelectivePlugin"
/>
</xml>
```
使用:
```
java
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
// 查询操作精确返回需要的列
this
.
tbMapper
.
selectByExampleSelective
(
new
TbExample
()
.
createCriteria
()
.
andField1GreaterThan
(
1
)
.
example
(),
Tb
.
Column
.
field1
,
Tb
.
Column
.
field2
);
// 同理还有 selectByPrimaryKeySelective,selectOneByExampleSelective(SelectOneByExamplePlugin插件配合使用)方法
}
}
```
\ No newline at end of file
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