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
6a0612bf
Commit
6a0612bf
authored
Nov 11, 2016
by
胡小根
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix query condition
parent
a4ed4fe1
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
404 additions
and
8 deletions
+404
-8
MybatisExampleHelper.java
...eekTruthBackend/service/HmUtils/MybatisExampleHelper.java
+41
-8
Tools.java
...m/haomostudio/SeekTruthBackend/service/HmUtils/Tools.java
+363
-0
No files found.
service/src/main/java/com/haomostudio/SeekTruthBackend/service/HmUtils/MybatisExampleHelper.java
View file @
6a0612bf
...
@@ -3,6 +3,7 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
...
@@ -3,6 +3,7 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
com.google.common.base.CaseFormat
;
import
com.haomostudio.SeekTruthBackend.service.HmUtils.Tools
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.util.*
;
import
java.util.*
;
...
@@ -39,10 +40,17 @@ public class MybatisExampleHelper {
...
@@ -39,10 +40,17 @@ public class MybatisExampleHelper {
* @return
* @return
*/
*/
public
static
String
getFilterFuncName
(
String
column
,
String
condition
){
public
static
String
getFilterFuncName
(
String
column
,
String
condition
){
if
(
column
.
contains
(
"_"
)){
return
"and"
return
"and"
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
column
)
+
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
UPPER_CAMEL
,
column
)
+
CaseFormat
.
LOWER_CAMEL
.
to
(
CaseFormat
.
UPPER_CAMEL
,
condition
);
+
CaseFormat
.
LOWER_CAMEL
.
to
(
CaseFormat
.
UPPER_CAMEL
,
condition
);
};
}
else
{
return
"and"
+
column
.
substring
(
0
,
1
).
toUpperCase
()
+
column
.
substring
(
1
)
+
CaseFormat
.
LOWER_CAMEL
.
to
(
CaseFormat
.
UPPER_CAMEL
,
condition
);
}
}
public
static
Method
getMethod
(
Object
obj
,
String
methodName
){
public
static
Method
getMethod
(
Object
obj
,
String
methodName
){
for
(
Method
m:
obj
.
getClass
().
getDeclaredMethods
()){
for
(
Method
m:
obj
.
getClass
().
getDeclaredMethods
()){
...
@@ -78,21 +86,46 @@ public class MybatisExampleHelper {
...
@@ -78,21 +86,46 @@ public class MybatisExampleHelper {
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
break
;
break
;
// 需要考虑时间和Number等字段
case
"between"
:
case
"between"
:
case
"notBetween"
:
case
"notBetween"
:
try
{
try
{
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"Date"
)){
m
.
invoke
(
exampleObjCriteria
,
Tools
.
convertStringToDate
(((
List
<
String
>)
value
).
get
(
0
),
"yyyy-MM-dd HH:mm:ss"
),
Tools
.
convertStringToDate
(((
List
<
String
>)
value
).
get
(
1
),
"yyyy-MM-dd HH:mm:ss"
));
}
else
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"Long"
)){
m
.
invoke
(
exampleObjCriteria
,
m
.
invoke
(
exampleObjCriteria
,
((
List
<
String
>)
value
).
get
(
0
),
((
List
<
Long
>)
value
).
get
(
0
),
((
List
<
String
>)
value
).
get
(
1
));
((
List
<
Long
>)
value
).
get
(
1
));
}
else
{
m
.
invoke
(
exampleObjCriteria
,
((
List
<
Integer
>)
value
).
get
(
0
),
((
List
<
Integer
>)
value
).
get
(
1
));
}
}
}
catch
(
ReflectiveOperationException
e
){
catch
(
ReflectiveOperationException
e
){
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
break
;
break
;
default
:
default
:
try
{
try
{
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"Date"
)){
m
.
invoke
(
exampleObjCriteria
,
Tools
.
convertStringToDate
((
String
)
value
,
"yyyy-MM-dd HH:mm:ss"
));
}
else
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"Long"
)){
m
.
invoke
(
exampleObjCriteria
,
Long
.
valueOf
((
String
)
value
));
}
else
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"Integer"
)){
m
.
invoke
(
exampleObjCriteria
,
Integer
.
valueOf
((
String
)
value
));
}
else
if
(
m
.
getParameterTypes
()[
0
].
getName
().
contains
(
"int"
)){
m
.
invoke
(
exampleObjCriteria
,
(
int
)
value
);
}
else
{
m
.
invoke
(
exampleObjCriteria
,
value
);
m
.
invoke
(
exampleObjCriteria
,
value
);
}
}
}
catch
(
ReflectiveOperationException
e
){
catch
(
ReflectiveOperationException
e
){
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
...
...
service/src/main/java/com/haomostudio/SeekTruthBackend/service/HmUtils/Tools.java
0 → 100644
View file @
6a0612bf
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