zoukankan      html  css  js  c++  java
  • springboot中帮助类中获取bean

    @Component
    public class OperationUtil implements ApplicationContextAware {
       // 获取redis接口
        private static RedisService redisService;
    
        @Override
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            if(redisService == null){
           // 从applicationContext中获取bean OperationUtil.redisService = (RedisService)applicationContext.getBean("redisService"); } } public static Operation saveOperation(Long hid, Long oid, Long pid, String content){ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); Operation op = null; String token = request.getHeader("token"); if (StringUtils.isNotEmpty(token)) { JWToken jwToken = new JWToken(); //获取解析token中的值 HashMap<String, Object> map = jwToken.parseJWT(token); Long uid = null; String account = null; if (map != null) { if (map.get("uid") != null && map.get("uid").toString() != "") { uid = Long.valueOf(map.get("uid").toString()); /*User user = userDao.getUserByUid(uid); if(user != null && user.getSid() != null){ sid = user.getSid(); }*/ if((hid == null || hid <= 0)){ if(redisService.get("hospital" + uid) != null){ hid = Long.valueOf((Integer)redisService.get("hospital" + uid)); } } } if (map.get("account") != null) { account = (String) map.get("account"); } op = new Operation(hid, oid, pid, uid, account, content); } }else{ op = new Operation(null, null, null, null, null, content); } return op; } public static Long getUserId(){ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); HttpServletRequest request = attributes.getRequest(); String token = request.getHeader("token"); JWToken jwToken = new JWToken(); //获取解析token中的值 HashMap<String,Object> map = jwToken.parseJWT(token); Long uid = null; if(map != null) { if (map.get("uid") != null && map.get("uid").toString() != "") { uid = Long.valueOf(map.get("uid").toString()); } } return uid; } }

      

  • 相关阅读:
    网络运维架构
    Q in Q
    光纤/光模块的多模和单模
    Cisco VTP
    Cisco NTP配置
    惠普/aruba交换机
    【转】交换机背板带宽
    接入交换机下所有服务器不定时丢包
    windows 2012安装不了KB2919355
    Cisco交换机密码策略设置
  • 原文地址:https://www.cnblogs.com/zhlblogs/p/10077435.html
Copyright © 2011-2022 走看看