Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
ZhangKuan
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
张宽
ZhangKuan
Commits
8b3d8351
Commit
8b3d8351
authored
Mar 16, 2018
by
22管33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加自動生成'或'的實現
parent
1b7a89e9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
131 additions
and
7 deletions
+131
-7
README.md
README.md
+28
-1
yanshi.jpeg
docs/image/yanshi.jpeg
+0
-0
Util.java
domain/src/main/java/com/haomostudio/Util/Util.java
+64
-0
pom.xml
pom.xml
+5
-5
MybatisExampleHelper.java
...eekTruthBackend/service/HmUtils/MybatisExampleHelper.java
+33
-0
mysqlGeneratorConfig.xml
web/src/main/resources/mybatis/mysqlGeneratorConfig.xml
+1
-1
No files found.
README.md
View file @
8b3d8351
...
...
@@ -32,4 +32,31 @@ postgresql
### 3.运行生成过程
运行mybatis_generate.sh文件,就在项目根目录下面。
### 4.备注
PS:项目根目录下面的脚本作用clean_mybatis_generated.sh和clean_mybatis_generated_springmvc.sh 删除相应目录下所有的文件。
\ No newline at end of file
PS:项目根目录下面的脚本作用clean_mybatis_generated.sh和clean_mybatis_generated_springmvc.sh 删除相应目录下所有的文件。
### 5.自动生成"或"的实现
1.
将下面的代码拷贝到生成
**xxxExample.java**
文件中,拷贝的位置为抽象类
**GeneratedCriteria**
中,如下图所示。
```
public Criteria filedsValueOr(List<String> fileds, String value, String column){
addCriterion(Util.dealDataBaseOR(fileds,value,column));
return (Criteria) this;
}
public Criteria filedValuesOr(List<String> fileds, String value, String column){
addCriterion(Util.dealValuesDataBaseOR(fileds,value,column));
return (Criteria) this;
}
public Criteria filedsValuesOr( List<String> fileds,List<String> values, String column){
addCriterion(Util.dealFieldsValuesDataBaseOR(fileds,values,column));
return (Criteria) this;
}
```
!
[
代码示例
](
docs/image/yanshi.jpeg
)
2.
将项目中的
**Util.java**
文件复制到自己的项目里。文件路径:domain/src/main/java/com/haomostudio/Util/Util.java
\ No newline at end of file
docs/image/yanshi.jpeg
0 → 100644
View file @
8b3d8351
340 KB
domain/src/main/java/com/haomostudio/Util/Util.java
0 → 100644
View file @
8b3d8351
package
com
.
haomostudio
.
Util
;
/**
* Created by guanpb on 2018/3/16.
*/
import
java.util.List
;
/**
* Created by guanpb on 2017/9/18.
*/
public
class
Util
{
public
static
String
dealDataBaseOR
(
List
<
String
>
fileds
,
String
value
,
String
column
){
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"( "
);
fileds
.
stream
().
forEach
(
filed
->{
if
(
column
.
contains
(
"like"
)){
stringBuffer
.
append
(
filed
+
" like '%"
+
value
+
"%' or "
);
}
else
{
stringBuffer
.
append
(
filed
+
" = '"
+
value
+
"' or "
);
}
});
stringBuffer
.
delete
(
stringBuffer
.
length
()-
4
,
stringBuffer
.
length
()-
1
);
stringBuffer
.
append
(
") "
);
return
stringBuffer
.
toString
();
}
public
static
String
dealValuesDataBaseOR
(
List
<
String
>
values
,
String
filed
,
String
column
){
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"( "
);
values
.
stream
().
forEach
(
value
->{
if
(
column
.
contains
(
"like"
)){
stringBuffer
.
append
(
filed
+
" like '%"
+
value
+
"%' or "
);
}
else
{
stringBuffer
.
append
(
filed
+
" = '"
+
value
+
"' or "
);
}
});
stringBuffer
.
delete
(
stringBuffer
.
length
()-
4
,
stringBuffer
.
length
()-
1
);
stringBuffer
.
append
(
") "
);
return
stringBuffer
.
toString
();
}
public
static
String
dealFieldsValuesDataBaseOR
(
List
<
String
>
fileds
,
List
<
String
>
values
,
String
column
){
StringBuffer
stringBuffer
=
new
StringBuffer
();
stringBuffer
.
append
(
"( "
);
int
i
=
0
;
for
(
String
value:
values
){
if
(
column
.
contains
(
"like"
)){
stringBuffer
.
append
(
fileds
.
get
(
i
)+
" like '%"
+
value
+
"%' or "
);
}
else
{
stringBuffer
.
append
(
fileds
.
get
(
i
)+
" = '"
+
value
+
"' or "
);
}
i
++;
}
stringBuffer
.
delete
(
stringBuffer
.
length
()-
4
,
stringBuffer
.
length
()-
1
);
stringBuffer
.
append
(
") "
);
return
stringBuffer
.
toString
();
}
}
\ No newline at end of file
pom.xml
View file @
8b3d8351
...
...
@@ -160,11 +160,11 @@
</dependency>
<!-- 添加oracle jdbc driver -->
<
!--<dependency>--
>
<
!--<groupId>com.oracle</groupId>--
>
<
!--<artifactId>ojdbc6</artifactId>--
>
<
!--<version>11.2.0.1.0</version>--
>
<
!--</dependency>--
>
<
dependency
>
<
groupId>
com.oracle
</groupId
>
<
artifactId>
ojdbc6
</artifactId
>
<
version>
11.2.0.1.0
</version
>
<
/dependency
>
...
...
service/src/main/java/com/haomostudio/SeekTruthBackend/service/HmUtils/MybatisExampleHelper.java
View file @
8b3d8351
...
...
@@ -89,6 +89,39 @@ public class MybatisExampleHelper {
Method
m
=
MybatisExampleHelper
.
getMethod
(
exampleObjCriteria
,
funcName
);
switch
(
condition
){
case
"filedsValueOr"
:
try
{
m
=
MybatisExampleHelper
.
getMethod
(
exampleObjCriteria
,
condition
);
m
.
invoke
(
exampleObjCriteria
,(
List
<
String
>)((
Map
<
String
,
Object
>)
value
).
get
(
"fileds"
),((
Map
<
String
,
Object
>)
value
).
get
(
"value"
),
column
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
break
;
case
"filedValuesOr"
:
try
{
m
=
MybatisExampleHelper
.
getMethod
(
exampleObjCriteria
,
condition
);
m
.
invoke
(
exampleObjCriteria
,(
List
<
String
>)((
Map
<
String
,
Object
>)
value
).
get
(
"values"
),((
Map
<
String
,
Object
>)
value
).
get
(
"filed"
),
column
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
break
;
case
"filedsValuesOr"
:
try
{
m
=
MybatisExampleHelper
.
getMethod
(
exampleObjCriteria
,
condition
);
m
.
invoke
(
exampleObjCriteria
,(
List
<
String
>)((
Map
<
String
,
Object
>)
value
).
get
(
"fileds"
),(
List
<
String
>)((
Map
<
String
,
Object
>)
value
).
get
(
"values"
),
column
);
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
break
;
case
"isNull"
:
case
"isNotNull"
:
try
{
...
...
web/src/main/resources/mybatis/mysqlGeneratorConfig.xml
View file @
8b3d8351
...
...
@@ -12,7 +12,7 @@
<plugin
type=
"org.mybatis.generator.plugins.ToStringPlugin"
/>
<jdbcConnection
driverClass=
"com.mysql.jdbc.Driver"
connectionURL=
"jdbc:mysql://haomo-
studio.com:3304/auction-
oa"
connectionURL=
"jdbc:mysql://haomo-
tech.com:3302/zhangjiakou
oa"
userId=
"root"
password=
"root"
/>
...
...
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