1.首先在web.xml配置
<listener>
<listener-class>DataDictionaryListener</listener-class>
</listener>
2.书写DataDictionaryListener类
public class DataDictionaryListener extends ContextLoader implements ServletContextListener{
private ArrayList<String> codeArrayList = new ArrayList<String>();//数据字典Code列表
@Override
public void contextInitialized(ServletContextEvent sce) {
//Spring上下文获取及Bean获取
ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
DataDictionaryService dataDictionaryService = (DataDictionaryService) applicationContext.getBean("dataDictionaryService");
ServletContext servletContext = sce.getServletContext();
//查询获取数据库所有数据字典Code列表
try {
codeArrayList = dataDictionaryService.getDataDictionaryCodeList();
}catch (Exception e){
System.out.println("============项目启动获取数据字典Code列表出错==================");
e.printStackTrace();
}
//循环CodeList初始化数据字典数据之内存中
try {
for (String code : codeArrayList) {
servletContext.setAttribute(code, dataDictionaryService.getDataDictionaryByStr(code));
}
}catch (Exception ex){
System.out.println("============项目启动存储数据字典列表至内存出错==================");
ex.printStackTrace();
}
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
closeWebApplicationContext(sce.getServletContext());
}
}
3.从内存中取出每个code对应的list集合dataDictionaryService方法
WebApplicationContext webApplicationContext = ContextLoader.getCurrentWebApplicationContext();
ServletContext servletContext = webApplicationContext.getServletContext();
arrayList = (ArrayList<DataDictionary>) servletContext.getAttribute(code);
获取到该code对应的arrayList数据。
最新评论
命令: nload
真是个良心站点哇,大公无私,爱了爱了
还可以直接搞一张映射表,存 uid | time | source_index, 第一次直接查对应的 time 选出前100, 第二次直接用 CompleteFuture 去分别用 source_in
干得漂亮,多个朋友堵条路
2021.2.2版本的不适用吧
现在还可以用么
激活码有用,感谢分享
激活码的地址打不开了