Commit 2e43830c by stylefeng

优化代码

parent 1f484cfb
package com.stylefeng.guns.common.annotion;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
/**
* 权限注解 用于检查权限 规定访问权限
*
* @example @Permission({roleID1,roleID2})
* @example @Permission({role1,role2})
* @example @Permission
*/
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Permission {
/**
* <p>角色英文名称</p>
* <p>使用注解时加上这个值表示限制只有某个角色的才可以访问对应的资源</p>
* <p>常用在某些资源限制只有超级管理员角色才可访问</p>
*/
String[] value() default {};
}
package com.stylefeng.guns.common.constant.cache;
/**
* 缓存的key集合
* 缓存标识前缀集合,常用在ConstantFactory类中
*
* @author fengshuonan
* @date 2017-04-25 9:37
......@@ -9,15 +9,23 @@ package com.stylefeng.guns.common.constant.cache;
public interface CacheKey {
/**
* ConstantFactory中的缓存
* 角色名称(多个)
*/
String ROLES_NAME = "roles_name_";
/**
* 角色名称(单个)
*/
String SINGLE_ROLE_NAME = "single_role_name_";
/**
* 角色英文名称
*/
String SINGLE_ROLE_TIP = "single_role_tip_";
/**
* 部门名称
*/
String DEPT_NAME = "dept_name_";
}
......@@ -8,24 +8,22 @@ import com.stylefeng.guns.core.exception.GunsException;
import java.lang.reflect.Method;
/**
* 字段的包装创建工厂
* 字典字段的包装器(从ConstantFactory中获取包装值)
*
* @author fengshuonan
* @date 2017-05-06 15:12
*/
public class DictFieldWarpperFactory {
public static Object createFieldWarpper(Object field, String methodName) {
IConstantFactory me = ConstantFactory.me();
public static Object createFieldWarpper(Object parameter, String methodName) {
IConstantFactory constantFactory = ConstantFactory.me();
try {
Method method = IConstantFactory.class.getMethod(methodName, field.getClass());
Object result = method.invoke(me, field);
return result;
Method method = IConstantFactory.class.getMethod(methodName, parameter.getClass());
return method.invoke(constantFactory, parameter);
} catch (Exception e) {
try {
Method method = IConstantFactory.class.getMethod(methodName, Integer.class);
Object result = method.invoke(me, Integer.parseInt(field.toString()));
return result;
return method.invoke(constantFactory, Integer.parseInt(parameter.toString()));
} catch (Exception e1) {
throw new GunsException(BizExceptionEnum.ERROR_WRAPPER_FIELD);
}
......
......@@ -16,7 +16,6 @@ public enum BizExceptionEnum implements ServiceExceptionEnum{
ERROR_CREATE_DICT(500,"创建字典失败"),
ERROR_WRAPPER_FIELD(500,"包装字典属性失败"),
/**
* 文件上传
*/
......
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