Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
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
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
YZG
yzg-util
Commits
35159db3
Commit
35159db3
authored
May 15, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置打包时可以通过GIT查看源码
parent
178e8a4b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
4 deletions
+93
-4
TypeHelper.java
...src/main/java/com/yanzuoguang/util/helper/TypeHelper.java
+31
-4
TestTypeHelper.java
yzg-util-base/src/test/java/helper/TestTypeHelper.java
+30
-0
ResponseDataMainResult.java
...-base/src/test/java/helper/vo/ResponseDataMainResult.java
+32
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/TypeHelper.java
View file @
35159db3
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
java.lang.reflect.ParameterizedType
;
import
java.lang.reflect.Type
;
...
...
@@ -21,8 +19,24 @@ public class TypeHelper {
*/
public
static
boolean
isSubType
(
Type
from
,
Class
to
)
{
Class
returnClass
=
getClass
(
from
);
boolean
isResponseResult
=
returnClass
!=
null
&&
returnClass
.
isAssignableFrom
(
ResponseResult
.
class
);
return
isResponseResult
;
return
isSubClass
(
returnClass
,
to
);
}
/**
* 判断是否属于子类
*
* @param from
* @param to
* @return
*/
public
static
boolean
isSubClass
(
Class
from
,
Class
to
)
{
if
(
from
==
null
)
{
return
false
;
}
if
(
from
.
isAssignableFrom
(
to
))
{
return
true
;
}
return
isSubClass
(
from
.
getSuperclass
(),
to
);
}
/**
...
...
@@ -40,4 +54,17 @@ public class TypeHelper {
}
return
null
;
}
/**
* 打印类型
*
* @param returnType
*/
public
static
void
printSuperClass
(
Class
<?>
returnType
)
{
if
(
returnType
==
null
)
{
return
;
}
System
.
out
.
println
(
returnType
.
getName
());
printSuperClass
(
returnType
.
getSuperclass
());
}
}
yzg-util-base/src/test/java/helper/TestTypeHelper.java
0 → 100644
View file @
35159db3
package
helper
;
import
base.DemoVo
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.TypeHelper
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
helper.vo.ResponseDataMainResult
;
import
org.junit.Test
;
import
java.lang.reflect.Method
;
import
java.util.List
;
public
class
TestTypeHelper
{
public
ResponseDataMainResult
<
List
<
DemoVo
>,
DemoVo
>
getReturnType
()
{
return
null
;
}
@Test
public
void
test
()
throws
NoSuchMethodException
{
// 获取泛型的返回值类型
Method
method
=
TestTypeHelper
.
class
.
getMethod
(
"getReturnType"
);
Class
<?>
returnType
=
method
.
getReturnType
();
TypeHelper
.
printSuperClass
(
returnType
);
boolean
isSub
=
TypeHelper
.
isSubType
(
returnType
,
ResponseResult
.
class
);
if
(!
isSub
)
{
throw
new
CodeException
(
"泛型继承检测错误"
);
}
}
}
yzg-util-base/src/test/java/helper/vo/ResponseDataMainResult.java
0 → 100644
View file @
35159db3
package
helper
.
vo
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
/**
* 评论结果查看结果
*
* @author 颜佐光
*/
@ApiModel
(
description
=
"评论结果查看结果"
)
public
class
ResponseDataMainResult
<
T
extends
Object
,
M
extends
Object
>
extends
ResponseResult
<
T
>
{
/**
* 主表数据,在状态成功时有效
*/
@ApiModelProperty
(
value
=
"主表数据"
,
notes
=
"主表数据,在状态成功时有效"
,
required
=
true
)
private
M
main
;
public
M
getMain
()
{
return
main
;
}
public
void
setMain
(
M
main
)
{
this
.
main
=
main
;
}
}
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