与spring的相关代码,开发中的经验总结
1.在基于 Spring 的 web 项目中,我们可以随时随地获取到当前请求,获取方式就是下面给出的代码:
HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
String code = req.getParameter("code");
2.spring项目一启动就加载某些操作的代码示例:
@Component public class DicCacheManage implements ApplicationContextAware { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { log.info("=======开始加载字典缓存======"); DicMap.initDicts(applicationContext); log.info("=======结束加载字典缓存======"); } }