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
aed50eb7
Commit
aed50eb7
authored
Jul 28, 2017
by
22管33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加refers和includes处理的方法
parent
f86bfab5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
MybatisExampleHelper.java
...eekTruthBackend/service/HmUtils/MybatisExampleHelper.java
+92
-0
No files found.
service/src/main/java/com/haomostudio/SeekTruthBackend/service/HmUtils/MybatisExampleHelper.java
View file @
aed50eb7
...
...
@@ -3,7 +3,10 @@ package com.haomostudio.SeekTruthBackend.service.HmUtils;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.CaseFormat
;
import
org.springframework.web.context.ContextLoader
;
import
org.springframework.web.context.WebApplicationContext
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.*
;
...
...
@@ -213,4 +216,93 @@ public class MybatisExampleHelper {
}});
}});
}
/**
*
* @param m java反射类中的方法
* @param superior 实体类对象
* @param className 类名(用于反射时对应的ServiceImpl类)
* @param map 用于存储数据的Map
* @param table 关联表的名字
*/
public
static
void
dealSearchIncludes
(
Method
m
,
Object
superior
,
Object
className
,
Map
<
String
,
Object
>
map
,
String
table
,
String
packageName
){
try
{
if
(
m
!=
null
){
//外联表的主键值
Object
id
=
m
.
invoke
(
superior
);
//根据主键取出整条数据
if
(
id
!=
null
){
WebApplicationContext
wac
=
ContextLoader
.
getCurrentWebApplicationContext
();
//反射类名
Class
onwClass
=
Class
.
forName
(
packageName
+
"."
+
className
+
"ServiceImpl"
);
Object
impl
=
onwClass
.
newInstance
();
//获取Method的对象
String
get
=
"get"
;
if
(
className
.
equals
(
"CrmUser"
)){
get
=
"getUserById"
;
}
Method
m1
=
MybatisExampleHelper
.
getMethod
(
impl
,
get
);
if
(
m1
!=
null
){
//外联表的整条数据
Object
obj2
=
m1
.
invoke
(
wac
.
getBean
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Service"
),
id
);
//取出来的数据返回
map
.
put
(
table
.
toString
(),
obj2
);
}
}
}
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
dealSearchRefers
(
Object
id
,
String
table
,
Map
<
String
,
List
<
Object
>>
map
,
Object
obj
,
Object
className
,
String
packageName
){
try
{
//根据主键取出整条数据
if
(
id
!=
null
)
{
WebApplicationContext
wac
=
ContextLoader
.
getCurrentWebApplicationContext
();
//DivStattisTabService service = (DivStattisTabService)
//反射类名
Class
onwClass
=
Class
.
forName
(
packageName
+
"."
+
className
+
"ServiceImpl"
);
Object
impl
=
onwClass
.
newInstance
();
//获取Method的对象
Method
m1
=
MybatisExampleHelper
.
getMethodNumber
(
impl
,
"getListWithPagingAndFilter"
,
5
);
//filters的字符串拼接
StringBuffer
buffer
=
new
StringBuffer
();
buffer
.
append
(
"{"
);
buffer
.
append
(
"\""
+
table
+
"\""
);
buffer
.
append
(
":{"
);
buffer
.
append
(
"\""
+
obj
.
toString
()+
"\""
);
buffer
.
append
(
":{"
);
buffer
.
append
(
"\"equalTo\": \""
+
id
.
toString
()+
"\""
);
buffer
.
append
(
"} } }"
);
//执行getListWithPagingAndFilter方法的参数数组
Object
[]
methodObject
=
new
Object
[]{
1
,
1000
,
"id"
,
"asc"
,
buffer
.
toString
()};
if
(
m1
!=
null
){
//外联表的整条数据
List
<
Object
>
obj2
=
(
List
<
Object
>)
m1
.
invoke
(
wac
.
getBean
(
CaseFormat
.
LOWER_UNDERSCORE
.
to
(
CaseFormat
.
LOWER_CAMEL
,
table
)+
"Service"
),
1
,
1000
,
"id"
,
"asc"
,
buffer
.
toString
());
//取出来的数据返回
map
.
put
(
table
.
toString
(),
obj2
);
}
}
}
catch
(
IllegalAccessException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvocationTargetException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
InstantiationException
e
)
{
e
.
printStackTrace
();
}
}
}
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