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
be954aaf
Commit
be954aaf
authored
May 12, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常处理显示
parent
f21e0908
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
1 deletion
+30
-1
TokenHelper.java
...l-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
+30
-1
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
View file @
be954aaf
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.token;
import
com.yanzuoguang.util.base.ObjectHelper
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.MapRow
;
...
...
@@ -34,9 +35,24 @@ public class TokenHelper {
* @return 缓存的数据
*/
public
static
<
T
extends
Object
>
T
get
(
Class
<
T
>
cls
)
{
return
get
(
true
,
cls
);
}
/**
* 获取当前的登录信息
*
* @param checkFlag 是否抛出异常
* @param cls 需要获取的数据的类型
* @param <T> 数据类型
* @return 缓存的数据
*/
public
static
<
T
extends
Object
>
T
get
(
boolean
checkFlag
,
Class
<
T
>
cls
)
{
String
id
=
getCurrentId
();
TokenData
tokenData
=
cache
.
get
(
id
);
if
(
tokenData
==
null
||
tokenData
.
getData
()
==
null
)
{
if
(
checkFlag
)
{
throw
new
CodeException
(
"请先登录"
);
}
return
null
;
}
if
(
ObjectHelper
.
isSub
(
cls
,
tokenData
.
getData
().
getClass
()))
{
...
...
@@ -56,7 +72,20 @@ public class TokenHelper {
* @return 对象
*/
public
static
<
T
extends
Object
>
T
getField
(
Class
<
T
>
cls
,
String
field
)
{
MapRow
row
=
get
(
MapRow
.
class
);
return
getField
(
true
,
cls
,
field
);
}
/**
* 获取字段值
*
* @param checkFlag 是否抛出异常
* @param cls 字段值类型
* @param field 字段值
* @param <T> 类型
* @return 对象
*/
public
static
<
T
extends
Object
>
T
getField
(
boolean
checkFlag
,
Class
<
T
>
cls
,
String
field
)
{
MapRow
row
=
get
(
checkFlag
,
MapRow
.
class
);
Object
value
=
null
;
if
(
row
.
containsKey
(
field
))
{
value
=
row
.
get
(
field
);
...
...
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