Java Code Examples for com.baomidou.mybatisplus.toolkit.ReflectionKit#getSuperClassGenricType()

The following examples show how to use com.baomidou.mybatisplus.toolkit.ReflectionKit#getSuperClassGenricType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CriteriaParserFactory.java    From cola-cloud with MIT License 5 votes vote down vote up
/**
 * 注册解析器
 * @param conditionParser
 */
public static void register(ConditionParser conditionParser) {
    Class<?> type = ReflectionKit.getSuperClassGenricType(conditionParser.getClass(), 0);
    if (log.isDebugEnabled()) {
        log.debug("CriteriaContext Parser {0} was registered on {1}", conditionParser, type);
    }
    repository.put(type, conditionParser);
}
 
Example 2
Source File: GenericService.java    From bird-java with MIT License 5 votes vote down vote up
@SuppressWarnings("all")
protected Class<T> getModelClass(){
    if(modelClass == null){
        synchronized (this){
            if(modelClass == null){
                modelClass = (Class<T>)ReflectionKit.getSuperClassGenricType(getClass(), 1);
            }
        }
    }
    return modelClass;
}
 
Example 3
Source File: GenericService.java    From bird-java with MIT License 5 votes vote down vote up
@SuppressWarnings("all")
protected Class<TKey> getKeyClass(){
    if(keyClass == null){
        synchronized (this){
            if(keyClass == null){
                keyClass = (Class<TKey>)ReflectionKit.getSuperClassGenricType(getClass(), 1);
            }
        }
    }
    return keyClass;
}
 
Example 4
Source File: BaseAuthInterceptor.java    From Ffast-Java with MIT License 4 votes vote down vote up
/**
 * 拦截登录&权限
 *
 * @param request
 * @param response
 * @param handler
 * @return
 * @throws Exception
 */
@Override
public boolean preHandle(HttpServletRequest request,
                         HttpServletResponse response, Object handler) throws Exception {
    logger.debug("###############进入拦截器###############");
    String path = (request.getRequestURI().replace(request.getContextPath(), ""));
    StringBuilder permissionName = new StringBuilder();
    boolean loginVerify = false;

    HandlerMethod hMethod = null;
    String beanName = null;
    if (handler instanceof HandlerMethod) {
        hMethod = ((HandlerMethod) handler);
        Object bean = hMethod.getBean();
        Logined loginedClassAnnotation = bean.getClass().getAnnotation(Logined.class);
        Logined loginedMethodAnnotation = hMethod.getMethodAnnotation(Logined.class);
        if (loginedClassAnnotation != null) {
            if (loginedClassAnnotation.notEffectSelf() &&
                    hMethod.getMethod().getDeclaringClass().getName().equals(bean.getClass().getName())) {
                loginVerify = false;
            } else {
                loginVerify = true;
            }
        }
        if (loginedMethodAnnotation != null) {
            if (loginedMethodAnnotation.notEffectSelf()) {
                loginVerify = false;
            } else {
                loginVerify = true;
            }
        }
        Permission classPermission = bean.getClass().getAnnotation(Permission.class);
        Permission methodPermission = hMethod.getMethodAnnotation(Permission.class);


        if (methodPermission != null) {
            //如果是独立的权限验证
            if (methodPermission.alone()) {
                permissionName = new StringBuilder(methodPermission.value());
            } else {
                // 如果方法权限不为空才会和类权限组合
                if (classPermission != null && StringUtils.isNotEmpty(methodPermission.value())) {
                    permissionName.append(classPermission.value());
                    permissionName.append(":");
                    permissionName.append(methodPermission.value());
                }
            }
        }
        beanName = bean.getClass().getName();
    }

    if (loginVerify) {
        Class<T> tClass = ReflectionKit.getSuperClassGenricType(this.getClass(), 0);
        T loginUser = operatorUtils.getTokenUser(request, tClass);
        request.setAttribute("loginUser", loginUser);
        if (loginUser == null) {
            //未登录
            notLogin(response);
            logger.error(beanName + " path:" + path + " [未登录]");
            return false;
        } else if (StringUtils.isNotEmpty(permissionName) &&
                !verifyPerms(loginUser.getHasRoleId(), permissionName.toString())) {
            //没有权限
            notPermission(response);
            logger.error(beanName + " loginId:" + loginUser.getUserId() +
                    " loginName:" + loginUser.getUserName() + " funcId:" + permissionName + " [没有权限]");
            return false;
        }
    }

    return true;

}
 
Example 5
Source File: BaseService.java    From Ffast-Java with MIT License 4 votes vote down vote up
@Override
protected Class<T> currentModelClass() {
    return ReflectionKit.getSuperClassGenricType(this.getClass(), 1);
}
 
Example 6
Source File: BaseServiceImpl.java    From cola-cloud with MIT License 4 votes vote down vote up
/**
 * 获取泛型类型
 * @return
 */
@SuppressWarnings("unchecked")
protected Class<T> currentModelClass() {
    return ReflectionKit.getSuperClassGenricType(getClass(), 0);
}