feat:Dict注解支持单个对象返回的场景
This commit is contained in:
@@ -81,8 +81,8 @@ public class DictAspect {
|
||||
if (!(result instanceof CommonResult))
|
||||
return result;
|
||||
Object data = ((CommonResult) result).getData();
|
||||
if (!(data instanceof PageResult<?>) && !(data instanceof ArrayList<?>))
|
||||
return result;
|
||||
// if (!(data instanceof PageResult<?>) && !(data instanceof ArrayList<?>))
|
||||
// return result;
|
||||
List<JSONObject> items = new ArrayList<>();
|
||||
|
||||
//step.1 筛选出加了 Dict 注解的字段列表
|
||||
@@ -92,6 +92,7 @@ public class DictAspect {
|
||||
//取出结果集
|
||||
List records = new ArrayList();
|
||||
String instanceType = "";
|
||||
boolean singleDataFlag = false;
|
||||
if(data instanceof PageResult<?>){
|
||||
records = ((PageResult) data).getList();
|
||||
instanceType = "PageResult";
|
||||
@@ -99,6 +100,9 @@ public class DictAspect {
|
||||
else if(data instanceof ArrayList<?>){
|
||||
records = (List) data;
|
||||
instanceType = "ArrayList";
|
||||
}else{
|
||||
records.add( data);
|
||||
singleDataFlag = true;
|
||||
}
|
||||
|
||||
Boolean hasDict= checkHasDict(records);
|
||||
@@ -193,6 +197,9 @@ public class DictAspect {
|
||||
((ArrayList) data).clear();
|
||||
((ArrayList) data).addAll(items);
|
||||
}
|
||||
if(singleDataFlag){
|
||||
((CommonResult<JSONObject>) result).setData( items.get(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user