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
adbfe3a2
Commit
adbfe3a2
authored
Feb 05, 2018
by
hewei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[issues#20]:selectByExampleSelective 不支持 distinct
parent
f3d2a6fd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
3 deletions
+18
-3
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
...tfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
+7
-0
src/test/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePluginTest.java
.../mybatis/generator/plugins/SelectSelectivePluginTest.java
+10
-3
src/test/resources/scripts/SelectSelectivePlugin/init.sql
src/test/resources/scripts/SelectSelectivePlugin/init.sql
+1
-0
No files found.
src/main/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePlugin.java
View file @
adbfe3a2
...
@@ -189,6 +189,13 @@ public class SelectSelectivePlugin extends BasePlugin {
...
@@ -189,6 +189,13 @@ public class SelectSelectivePlugin extends BasePlugin {
if
(
stringHasValue
(
introspectedTable
.
getSelectByExampleQueryId
()))
{
if
(
stringHasValue
(
introspectedTable
.
getSelectByExampleQueryId
()))
{
selectByExampleSelectiveEle
.
addElement
(
new
TextElement
(
"'"
+
introspectedTable
.
getSelectByExampleQueryId
()
+
"' as QUERYID,"
));
selectByExampleSelectiveEle
.
addElement
(
new
TextElement
(
"'"
+
introspectedTable
.
getSelectByExampleQueryId
()
+
"' as QUERYID,"
));
}
}
// issues#20
XmlElement
ifDistinctElement
=
new
XmlElement
(
"if"
);
ifDistinctElement
.
addAttribute
(
new
Attribute
(
"test"
,
"example.distinct"
));
ifDistinctElement
.
addElement
(
new
TextElement
(
"distinct"
));
selectByExampleSelectiveEle
.
addElement
(
ifDistinctElement
);
selectByExampleSelectiveEle
.
addElement
(
columnsEle
);
selectByExampleSelectiveEle
.
addElement
(
columnsEle
);
selectByExampleSelectiveEle
.
addElement
(
new
TextElement
(
"from "
+
introspectedTable
.
getAliasedFullyQualifiedTableNameAtRuntime
()));
selectByExampleSelectiveEle
.
addElement
(
new
TextElement
(
"from "
+
introspectedTable
.
getAliasedFullyQualifiedTableNameAtRuntime
()));
...
...
src/test/java/com/itfsw/mybatis/generator/plugins/SelectSelectivePluginTest.java
View file @
adbfe3a2
...
@@ -79,7 +79,7 @@ public class SelectSelectivePluginTest {
...
@@ -79,7 +79,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
// 2. 执行sql
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
Assert
.
assertEquals
(
list
.
size
(),
3
);
Assert
.
assertEquals
(
list
.
size
(),
4
);
int
index
=
0
;
int
index
=
0
;
for
(
Object
obj
:
list
)
{
for
(
Object
obj
:
list
)
{
if
(
index
==
1
)
{
if
(
index
==
1
)
{
...
@@ -99,6 +99,13 @@ public class SelectSelectivePluginTest {
...
@@ -99,6 +99,13 @@ public class SelectSelectivePluginTest {
index
++;
index
++;
}
}
// 3. 测试 distinct
tbExample
.
invoke
(
"setDistinct"
,
true
);
String
sql1
=
SqlHelper
.
getFormatMapperSql
(
tbMapper
.
getObject
(),
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
Assert
.
assertEquals
(
sql1
,
"select distinct field1 from tb WHERE ( id < '100' ) order by field2 asc"
);
List
list1
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
Assert
.
assertEquals
(
list1
.
size
(),
3
);
}
}
});
});
}
}
...
@@ -228,7 +235,7 @@ public class SelectSelectivePluginTest {
...
@@ -228,7 +235,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
// 2. 执行sql
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
Assert
.
assertEquals
(
list
.
size
(),
3
);
Assert
.
assertEquals
(
list
.
size
(),
4
);
int
index
=
0
;
int
index
=
0
;
for
(
Object
obj
:
list
)
{
for
(
Object
obj
:
list
)
{
if
(
index
==
0
)
{
if
(
index
==
0
)
{
...
@@ -282,7 +289,7 @@ public class SelectSelectivePluginTest {
...
@@ -282,7 +289,7 @@ public class SelectSelectivePluginTest {
// 2. 执行sql
// 2. 执行sql
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
List
list
=
(
List
)
tbMapper
.
invoke
(
"selectByExampleSelective"
,
tbExample
.
getObject
(),
columns1
);
Assert
.
assertEquals
(
list
.
size
(),
3
);
Assert
.
assertEquals
(
list
.
size
(),
4
);
int
index
=
0
;
int
index
=
0
;
for
(
Object
obj
:
list
)
{
for
(
Object
obj
:
list
)
{
if
(
index
==
0
)
{
if
(
index
==
0
)
{
...
...
src/test/resources/scripts/SelectSelectivePlugin/init.sql
View file @
adbfe3a2
...
@@ -32,6 +32,7 @@ CREATE TABLE `tb` (
...
@@ -32,6 +32,7 @@ CREATE TABLE `tb` (
INSERT
INTO
`tb`
VALUES
(
'1'
,
'fd1'
,
null
);
INSERT
INTO
`tb`
VALUES
(
'1'
,
'fd1'
,
null
);
INSERT
INTO
`tb`
VALUES
(
'2'
,
null
,
'2'
);
INSERT
INTO
`tb`
VALUES
(
'2'
,
null
,
'2'
);
INSERT
INTO
`tb`
VALUES
(
'3'
,
'fd3'
,
'3'
);
INSERT
INTO
`tb`
VALUES
(
'3'
,
'fd3'
,
'3'
);
INSERT
INTO
`tb`
VALUES
(
'4'
,
'fd3'
,
'4'
);
-- ----------------------------
-- ----------------------------
-- Table structure for tb_blobs
-- Table structure for tb_blobs
...
...
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