优化field获取

This commit is contained in:
zhou-hao
2018-01-26 22:39:44 +08:00
parent 3c4e57b428
commit 33b24aa7d2
3 changed files with 8 additions and 18 deletions

View File

@@ -1,6 +1,7 @@
package org.hswebframework.web.dict.defaults;
import org.hswebframework.web.dict.*;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.*;
@@ -26,11 +27,9 @@ public class DefaultDictDefineRepository implements DictDefineRepository {
if (type == Object.class) {
return Collections.emptyList();
}
List<Field> lst = new ArrayList<>();
lst.addAll(Arrays.asList(type.getDeclaredFields()));
lst.addAll(parseField(type.getSuperclass()));
return lst;
List<Field> fields=new ArrayList<>();
ReflectionUtils.doWithFields(type, fields::add);
return fields;
}
@Override

View File

@@ -17,6 +17,7 @@ import org.hswebframework.web.entity.authorization.PermissionEntity;
import org.hswebframework.web.service.authorization.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.*;
@@ -111,11 +112,12 @@ public class AutoSyncPermission implements ApplicationListener<AuthorizeDefiniti
if (tmp instanceof AopAuthorizeDefinition) {
AopAuthorizeDefinition aopAuthorizeDefinition = ((AopAuthorizeDefinition) tmp);
Class type = aopAuthorizeDefinition.getTargetClass();
Class genType = ClassUtils.getGenericType(type);
Class genType = entityFactory.getInstanceType(ClassUtils.getGenericType(type));
List<OptionalField> optionalFields = new ArrayList<>();
entity.setOptionalFields(optionalFields);
if (genType != Object.class) {
Field[] fields = genType.getDeclaredFields();
List<Field> fields=new ArrayList<>();
ReflectionUtils.doWithFields(genType, fields::add);
for (Field field : fields) {
if ("id".equals(field.getName())) {
continue;

View File

@@ -8,38 +8,27 @@ import org.hswebframework.web.authorization.basic.aop.AopMethodAuthorizeDefiniti
import org.hswebframework.web.authorization.basic.aop.DefaultAopMethodAuthorizeDefinitionParser;
import org.hswebframework.web.authorization.define.AuthorizeDefinition;
import org.hswebframework.web.authorization.define.AuthorizeDefinitionInitializedEvent;
import org.hswebframework.web.commons.entity.GenericEntity;
import org.hswebframework.web.commons.entity.SimpleGenericEntity;
import org.hswebframework.web.commons.entity.factory.EntityFactory;
import org.hswebframework.web.commons.entity.factory.MapperEntityFactory;
import org.hswebframework.web.commons.entity.param.QueryParamEntity;
import org.hswebframework.web.controller.GenericEntityController;
import org.hswebframework.web.controller.SimpleGenericEntityController;
import org.hswebframework.web.controller.authorization.UserController;
import org.hswebframework.web.entity.authorization.PermissionEntity;
import org.hswebframework.web.service.CrudService;
import org.hswebframework.web.service.authorization.PermissionService;
import org.hswebframework.web.tests.SimpleWebApplicationTests;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
/**