zoukankan      html  css  js  c++  java
  • 工具类注入需要的service

    /**
     *  从redis获取信息
     * @author yy
     *
     */
    
    @Component//关键一:添加此注解才能被spring扫描到
    public class CacheUtil {
        
        private static Logger logger = LoggerFactory.getLogger(CacheUtil.class);
        
        @Autowired
        private JJWTUtils jwt;  //关键二:添加需要的服务类
        public static CacheUtil cacheUtil; //关键三:声明一个当前类的静态对象
        
        
        @PostConstruct  //关键四:通过@PostConstruct注解实现注入
        public void init() {
            cacheUtil = this;
            //cacheUtil.jwtUtils =  this.jwtUtils;
        }
        
        
        /**
         * 从Redis中获取登录的员工详细信息
         * @Title: getRedisEmp
         * @Description:
         * @return
         * @return EmployeVo
         * @author yy  2019-6-26 16:11:31
         */
        @SuppressWarnings("unused")
        private static EmployeVo getRedisEmp(HttpServletRequest request) {
            EmployeVo emp = null;
            JwtBodyBean jwtBody = cacheUtil.jwt.getJwtBody(request);
            if (jwtBody != null) {
                Long uid = jwtBody.getUid();
                Object jsonObj = cacheUtil.jwt.redisService.get(String.valueOf(uid));
                if (jsonObj != null) {
                    JSONObject json = JSONObject.parseObject(jsonObj.toString());
                    emp = new EmployeVo();
                    try {
                        emp.setEmId(json.getString("emId"));
                        emp.setDepartmentId(json.getString("departmentId"));
                        emp.setEmAccount(json.getString("emAccount"));
                        emp.setEmPassword(json.getString("emPassword"));
                        emp.setUserName(json.getString("userName"));
                        emp.setEmPhone(json.getString("emPhone"));
                        emp.setSeatId(json.getString("seatId"));
                        emp.setEmLevel(json.getIntValue("emLevel"));
                        emp.setCrmUserId(json.getString("crmUserId"));
                        emp.setAcAccount(json.getString("acAccount"));
                        emp.setAcPassword(json.getString("password"));
                        emp.setBs(json.getIntValue("bs"));
                        emp.setTs(json.getString("ts"));
                    } catch (Exception e) {
                        e.printStackTrace();
                        logger.error("从redis查询员工信息异常!", e.toString());
                    }
                }
            }
            return emp;
        }
    
    }

    转载自 https://blog.csdn.net/loveer0/article/details/83716040

  • 相关阅读:
    虚拟DOM和diff算法
    面向对象之封装
    面向对象之类和函数的属性
    面向对象之__init__方法
    面向对象之初始类和对象
    面向对象与面向过程详解
    CSS高级技巧
    CSS定位
    模块之re模块详解
    模块之logging模块详解
  • 原文地址:https://www.cnblogs.com/yangyang2018/p/11091349.html
Copyright © 2011-2022 走看看