• SpringUtil


    package cn.com.util;
    
    import java.util.Map;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServletRequest;
    import org.springframework.beans.BeansException;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.ApplicationContextAware;
    
    public class SpringUtil implements ApplicationContextAware {
    
        private static ApplicationContext applicationContext = null;
       
    
        public SpringUtil() {
        }
    
        public static void setApplicationContexts(ApplicationContext applicationContext) throws BeansException {
            SpringUtil.applicationContext = applicationContext;
        }
    
        public static ApplicationContext getApplicationContext() {
            return applicationContext;
        }
    
        public static <T> T getBean(String name) throws BeansException {
            return applicationContext.getBean(name);
        }
    
        public static Map<String, ?> getBeansOfType(Class<?> class1) {
            return applicationContext.getBeansOfType(class1);
        }
    
        public static <T> T getBean(Class<T> type) throws BeansException {
            return applicationContext.getBean(type);
        }
    
        public static <T> T getBean(String beanName, Class<T> type) throws BeansException {
            return applicationContext.getBean(beanName, type);
        }
    
        public static String getToken(HttpServletRequest request) {
            Cookie[] cookie = request.getCookies();
            if (cookie == null) {
                return null;
            } else {
                for(int i = 0; i < cookie.length; ++i) {
                    Cookie cook = cookie[i];
                    if (cook.getName().equals("SESSION") && !"".equals(cook.getValue() + "".trim())) {
                        return cook.getValue().toString();
                    }
                }
    
                return null;
            }
        }
    
        public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            SpringUtil.applicationContext = applicationContext;
        }
    }
  • 相关阅读:
    祈澈菇凉的高端知识资源分享星球开通
    使用mpvue开发小程序教程(五)
    使用mpvue开发小程序教程(四)
    使用mpvue开发小程序教程(三)
    使用mpvue开发小程序教程(二)
    使用mpvue开发小程序教程(一)
    手把手教你用vue-cli构建一个简单的路由应用
    wangEditor
    从列表中或数组中随机抽取固定数量的元素组成新的数组或列表
    js学习总结----核心解读
  • 原文地址:https://www.cnblogs.com/bevis-byf/p/14281488.html
Copyright © 2020-2023  润新知