多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
使用静态参数加载器可将系统某些静态参数表数据放入缓存,以便后续程序使用。 加载器配置文件:spring-params-loader.xml ``` <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd" default-autowire="byName"> <!-- 静态参数缓存加载器 --> <bean id="staticParamDataLoader" class="org.walkframework.base.system.staticparam.StaticParamDataLoader"> <!-- 缓存管理器 --> <property name="cacheManager" ref="springCacheManager"/> <!-- 是否每次启动时都加载。true:每次重新启动时都会强制重新加载。false:工程启动时,当发现本加载器已经加载过则放弃重新加载,但能否发现只有在redis环境下实现。 --> <property name="forceLoad" value="#{'${cache.params.forceLoad}'==''?('${cache.cacheDriver}'=='rediscache'?'false':'true'):'${cache.params.forceLoad}'}"/> <!-- 是否异步加载。true:开另外的线程进行加载,不影响工程启动速度 --> <property name="asynLoad" value="${cache.params.asynLoad}"/> <!-- 延迟加载秒数 --> <property name="delaySeconds" value="${cache.params.delaySeconds}"/> <!-- 是否启用自动刷新 --> <property name="autoRefresh" value="${cache.params.autoRefresh}"/> <!-- 自动刷新周期秒数 --> <property name="autoRefreshSeconds" value="${cache.params.autoRefreshSeconds}"/> <!-- 静态参数表配置文件列表 --> <property name="staticParams"> <util:list> <!-- 默认数据源静态参数表加载 --> <bean id="ds1_staticParamLoadManager" class="org.walkframework.base.system.staticparam.StaticParamLoadManager"> <property name="configLocation" value="spring/params/ds_1_params.xml"/><!-- 默认数据源静态参数表配置文件路径 --> <property name="dao" ref="sqlSessionDao"/><!-- 默认数据源dao工具 --> </bean> <!-- 其他数据源静态参数表加载示例 <bean id="ds2_staticParamLoadManager" class="org.walkframework.base.system.staticparam.StaticParamLoadManager"> <property name="configLocation" value="spring/params/ds_2_params.xml"/>数据源2静态参数表配置文件路径 <property name="dao" ref="sqlSessionDao2"/>数据源2dao工具 </bean> --> </util:list> </property> </bean> </beans> ``` 具体加载数据表配置文件:ds_1_params.xml ``` <?xml version="1.0" encoding="gb2312"?> <application> <!-- key: 缓存名称,唯一,不可重复。单表建议用表名,多表关联起个不会重复的名字。sql为空时,表示单表,以key作为表名。 必填--> <!-- primaryKey:主键。标识记录唯一的字段。 必填--> <!-- condition: 单表使用,条件限定。此字段不为空时表示单表查询,默认以key作为表名。 选填--> <!-- sqlId: 涉及到多表复杂查询时可自定义sql,在mybatis的sql文件里定义。 选填--> <!-- load: 是否加载,默认true。 选填--> <!-- ds_1数据库静态参数列表。如全部不加载可指定load="false",该值默认为true --> <StaticParams> <!-- 加载TD_S_STATIC表。此表特殊,程序中有特殊处理 --> <table key="TD_S_STATIC"/> <!-- 加载TD_M_STAFF全表。 --> <table key="TD_M_STAFF" primaryKey="STAFF_ID"/> <!-- 加载TD_M_DEPART全表。 --> <table key="TD_M_DEPART" primaryKey="DEPART_ID"/> <!-- 加载TD_M_AREA全表,条件限定为validflag='0'的数据 --> <table key="TD_M_AREA" primaryKey="AREA_CODE" condition="validflag='0'"/> <!-- 加载TD_S_CALLINGTYPE全表。 --> <table key="TD_S_CALLINGTYPE" primaryKey="CALLING_TYPE_CODE"/> <!-- 加载TD_S_CALLINGSUBTYPE全表。 --> <table key="TD_S_CALLINGSUBTYPE" primaryKey="CALLING_SUB_TYPE_CODE"/> <!-- 指定sql进行数据加载,ExampleSQL.selectStaffList在ExampleSQL.xml文件中定义 --> <table key="ExampleSQL.selectStaffList" primaryKey="STAFF_ID" sqlId="ExampleSQL.selectStaffList"/> </StaticParams> </application> ```