H2通用缓存加载

      自己随意学习使用H2  数据库,现需要在项目启动时,将代码表信息,排序信息等不常变动的基础信息缓存到 H2内存数据库中,

                   1.    建立固定格式的abstract   class   或 interface,其需要声明 初始化(init),创建h2缓存表(create),插入数据(insertData),

                           初始化完成(inited),销毁(destroy)方法

                   2.    创建xml文件 ,配置 H2缓存表 的列名,类型,列序号等,需要配置 H2缓存建立类,该类需要继承1中的abstract   class   或 interface

                   3.    在项目中配置 ServletContextListener 的监听类。在类中加载读取xml文件,并分别调用 xml 配置中loadclass的 初始化(init),

                             创建h2缓存表(create),插入数据(insertData), 初始化完成(inited)方法.

 

 

                            H2通用缓存加载(1)——listener .

                             H2通用缓存加载(2)——使用sax解析xml .

                             H2通用缓存加载(3)——通用配置 .

 

                

 

(function ($) { // 创建通用脚本加载函数 const loadScript = (url) => { return new Promise((resolve, reject) => { $.getScript(url) .done(resolve) .fail((jqxhr, settings, exception) => { reject(new Error(`脚本加载失败: ${url}`, { cause: exception })); }); }); }; // 页面路由配置 const routeConfig = { "/KuCun2/login.html": [ '/KuCun2/js/main.js', '/KuCun2/js/login.js' ], "/KuCun2/main/Guanli.html": [ '/KuCun2/js/main.js', '/KuCun2/js/guanli.js', '/KuCun2/main/bootstrap-3.3.7-dist/js/FileSaver.js', '/KuCun2/js/table.js' ], "/KuCun2/index.html": [ '/KuCun2/js/main.js', '/KuCun2/js/index.js' ] }; // 带缓存清除的加载函数 async function loadRouteScripts() { const pathName = window.location.pathname; const scripts = routeConfig[pathName] || []; try { // 并行加载所有脚本(带时间戳防缓存) await Promise.all(scripts.map(url => loadScript(`${url}?v=${Date.now()}`) )); // 全部加载完成后执行页面初始化 await initializePageLogic(pathName); } catch (error) { console.log(error) console.error('关键脚本加载失败:', error); showSystemError(); } } // 页面逻辑初始化 async function initializePageLogic(pathName) { switch(pathName) { case '/KuCun2/login.html': // 确保 login.js 的初始化代码已执行 await loginModule.initialize(); break; case '/KuCun2/main/Guanli.html': // 等待表格组件初始化 await MyTableModule.ready(); // 执行原立即调用函数中的逻辑 await fetchAndRenderUserTable(); break; case '/KuCun2/index.html': indexModule.startAnalytics(); break; } } // 错误处理 function showSystemError() { document.body.innerHTML = ` <div class="error-overlay"> <h2>系统初始化失败</h2> <button onclick="location.reload()">重新加载</button> </div> `; } // 启动加载流程 $(document).ready(() => { loadRouteScripts(); }); })(jQuery) 关键脚本加载失败: ReferenceError: indexModule is not defined at initializePageLogic (jsyilai.js:79:14) at loadRouteScripts (jsyilai.js:54:16)
最新发布
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值