Commit be954aaf authored by yanzg's avatar yanzg

异常处理显示

parent f21e0908
...@@ -2,6 +2,7 @@ package com.yanzuoguang.token; ...@@ -2,6 +2,7 @@ package com.yanzuoguang.token;
import com.yanzuoguang.util.base.ObjectHelper; import com.yanzuoguang.util.base.ObjectHelper;
import com.yanzuoguang.util.cache.MemoryCache; import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.exception.CodeException;
import com.yanzuoguang.util.helper.JsonHelper; import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper; import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.vo.MapRow; import com.yanzuoguang.util.vo.MapRow;
...@@ -34,9 +35,24 @@ public class TokenHelper { ...@@ -34,9 +35,24 @@ public class TokenHelper {
* @return 缓存的数据 * @return 缓存的数据
*/ */
public static <T extends Object> T get(Class<T> cls) { 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(); String id = getCurrentId();
TokenData tokenData = cache.get(id); TokenData tokenData = cache.get(id);
if (tokenData == null || tokenData.getData() == null) { if (tokenData == null || tokenData.getData() == null) {
if (checkFlag) {
throw new CodeException("请先登录");
}
return null; return null;
} }
if (ObjectHelper.isSub(cls, tokenData.getData().getClass())) { if (ObjectHelper.isSub(cls, tokenData.getData().getClass())) {
...@@ -56,7 +72,20 @@ public class TokenHelper { ...@@ -56,7 +72,20 @@ public class TokenHelper {
* @return 对象 * @return 对象
*/ */
public static <T extends Object> T getField(Class<T> cls, String field) { 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; Object value = null;
if (row.containsKey(field)) { if (row.containsKey(field)) {
value = row.get(field); value = row.get(field);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment