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
0c276b15
Commit
0c276b15
authored
May 19, 2017
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v1.0.9文档修正
parent
46d0b154
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
15 deletions
+66
-15
README.md
README.md
+66
-15
No files found.
README.md
View file @
0c276b15
...
...
@@ -14,6 +14,7 @@
*
[
数据Model属性对应Column获取插件(ModelColumnPlugin)
](
#8-数据model属性对应column获取插件
)
*
[
存在即更新插件(UpsertPlugin)
](
#9-存在即更新插件
)
*
[
Selective选择插入更新增强插件(SelectiveEnhancedPlugin)
](
#10-selective选择插入更新增强插件
)
*
[
Table增加前缀插件(TableSuffixPlugin)
](
#11-table增加前缀插件
)
---------------------------------------
Maven引用:
...
...
@@ -21,7 +22,7 @@ Maven引用:
<dependency>
<groupId>
com.itfsw
</groupId>
<artifactId>
mybatis-generator-plugin
</artifactId>
<version>
1.0.
8
</version>
<version>
1.0.
9
</version>
</dependency>
```
---------------------------------------
...
...
@@ -36,13 +37,23 @@ Maven引用:
```
java
public
interface
TbMapper
{
/**
*
这是Mybatis Generator拓展插件生成的方法(请勿删除)
.
*
This method was generated by MyBatis Generator
.
* This method corresponds to the database table tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
Tb
selectOneByExample
(
TbExample
example
);
/**
* This method was generated by MyBatis Generator.
* This method corresponds to the database table tb
*
* @mbg.generated
* @project https://github.com/itfsw/mybatis-generator-plugin
*/
// Model WithBLOBs 时才有
TbWithBLOBs
selectOneByExampleWithBLOBs
(
TbExample
example
);
}
```
### 2. MySQL分页插件
...
...
@@ -56,28 +67,29 @@ public interface TbMapper {
```
java
public
class
TbExample
{
/**
*
这是Mybatis Generator拓展插件生成的属性(请勿删除)
.
*
This field was generated by MyBatis Generator
.
* This field corresponds to the database table tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
protected
Integer
offset
;
/**
*
这是Mybatis Generator拓展插件生成的属性(请勿删除)
.
*
This field was generated by MyBatis Generator
.
* This field corresponds to the database table tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
protected
Integer
rows
;
/**
*
这是Mybatis Generator拓展插件生成的方法(请勿删除)
.
* This method corresponds to the database table
rc_user_token
*
This method was generated by MyBatis Generator
.
* This method corresponds to the database table
tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
public
TbExample
limit
(
Integer
rows
)
{
this
.
rows
=
rows
;
...
...
@@ -85,11 +97,11 @@ public class TbExample {
}
/**
*
这是Mybatis Generator拓展插件生成的方法(请勿删除)
.
* This method corresponds to the database table
rc_user_token
*
This method was generated by MyBatis Generator
.
* This method corresponds to the database table
tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
public
TbExample
limit
(
Integer
offset
,
Integer
rows
)
{
this
.
offset
=
offset
;
...
...
@@ -98,11 +110,11 @@ public class TbExample {
}
/**
*
这是Mybatis Generator拓展插件生成的方法(请勿删除)
.
*
This method was generated by MyBatis Generator
.
* This method corresponds to the database table tb
*
* @mbg.generated
* @
author hewei
* @
project https://github.com/itfsw/mybatis-generator-plugin
*/
public
TbExample
page
(
Integer
page
,
Integer
pageSize
)
{
this
.
offset
=
page
*
pageSize
;
...
...
@@ -478,6 +490,14 @@ public class Test {
.
example
()
);
// upsertByExampleSelective 用法类似
// 当Model WithBLOBs 存在时上述方法增加对应的 WithBLOBs 方法,举例如下:
TbWithBLOBs
tb3
=
new
Tb
.
Builder
()
.
field1
(
1
)
.
field2
(
"xx0"
)
.
delFlag
(
Tb
.
DEL_FLAG_ON
)
.
build
();
int
k6
=
this
.
tbMapper
.
upsertWithBLOBs
(
tb
);
}
}
```
...
...
@@ -530,4 +550,35 @@ public class Test {
);
}
}
```
### 11. Table增加前缀插件
项目中有时会遇到配置多数据源对应多业务的情况,这种情况下可能会出现不同数据源出现重复表名,造成异常冲突。
该插件允许为表增加前缀,改变最终生成的Model、Mapper、Example类名以及xml名。
插件:
```
xml
<!-- Table增加前缀插件 -->
<xml>
<plugin
type=
"com.itfsw.mybatis.generator.plugins.TableSuffixPlugin"
>
<!-- 这里配置的是全局表前缀,当然在table中配置的值会覆盖该全局配置 -->
<property
name=
"suffix"
value=
"Cm"
/>
</plugin>
<table
tableName=
"tb"
>
<!-- 这里可以单独表配置前缀,覆盖全局配置 -->
<property
name=
"suffix"
value=
"Db1"
/>
</table>
</xml>
```
使用:
```
java
public
class
Test
{
public
static
void
main
(
String
[]
args
)
{
// Tb 表对应的Model、Mapper、Example类都增加了Db1的前缀
// Model类名: Tb -> Db1Tb
// Mapper类名: TbMapper -> Db1TbMapper
// Example类名: TbExample -> Db1TbExample
// xml文件名: TbMapper.xml -> Db1TbMapper.xml
}
}
```
\ 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