zoukankan      html  css  js  c++  java
  • java 反射获取设置私有成员变量的值

    for (Object arg:args) {
                //处理applicationCode
                Class<?> argClass = arg.getClass();
                Field applicationCode =null;
                try {
                    applicationCode =argClass.getDeclaredField("applicationCode");
                }catch (NoSuchFieldException e){
    
                }
                JWTData jwtData = CurrentUser.getUserInfo();
                if (applicationCode!=null&&jwtData != null){
                    applicationCode.setAccessible(true);
                    if ( StringUtils.isNotEmpty(jwtData.getApplicationCode())) {
                        applicationCode.set(arg,jwtData.getApplicationCode());
                    }
                }
                //处理 createdBy
                Field createdBy = null;
                try {
                    createdBy =argClass.getDeclaredField("createdBy");
                }catch (NoSuchFieldException e){
    
                }
                createdBy.setAccessible(true);
                if (createdBy !=null&&createdBy.get(arg)==null &&jwtData != null){
                    if ( StringUtils.isNotEmpty(jwtData.getUsername())) {
                        createdBy.set(arg,jwtData.getUsername());
                    }
                }
            }
  • 相关阅读:
    emacs jedi
    opencv 基本demo
    emacs列编辑
    observable operator example
    angular keydown 例子
    回调和匿名函数
    gin cors
    angular rxjs
    python dbus note
    视频截图
  • 原文地址:https://www.cnblogs.com/z-test/p/10855745.html
Copyright © 2011-2022 走看看