常量配置表可以通过启动服务的方式,把这些信息加入缓存中,当需要调用的时候,直接通过key来获取对应的value值,还有一些其它的表,但是有些信息需要加入缓存中,这些中的字段也符合对应的Type,key,value;即符合常量配置表中的结构
如何通过配置就可以完成各个其它的表加入缓存中,把对应的key与value赋值给对应的SysConstsBean中,这样就可以通过更改xml中的配置文件来处理,代码的复用性更高,有类似结构的存储就可以采用这种方式,而不是 一个表写一个类对应存储
step1:首先在xml配置文件中给定义的 List<Map<String, String>> consts = new ArrayList<Map<String, String>>();
<bean id="SysConstsBean" class="com.zycfc.fps.admin.common.constants.SysConstsBean">
<property name="consts">
<list>
<map>
<entry key="type" value="BANK_CDE_CONF"/>
<entry key="key" value="ACC_BANK_CDE"/>
<entry key="value" value="ACC_BANK_NAME"/>
<entry key="tableName" value="S_ACC_BANK"/>
<entry key="where" value="BANK_STS='A'"/>
<entry key="orderby" value="ACC_BANK_CDE,ACC_BANK_NAME "/>
</map>
</list>
</property>
</bean>
public class SysConstsBean {
List<Map<String, String>> consts = new ArrayList<Map<String, String>>();
public List<Map<String, String>> getConsts() {
return consts;
}
public void setConsts(List<Map<String, String>> consts) {
this.consts = consts;
}
}
2、当把对应的值通过配置写入类中,就可以获取xml配置信息中的值,然后以参数的形式传入到需要查询的语句中。
@Component
public class SysInitService {
private Logger LOGGER = LoggerFactory.getLogger(SysInitService.class);
@Autowired
private BaseConfService baseConfService;
@Autowired
private SysConstsBean sysConstsBean;
@PostConstruct
public void init() {
LOGGER.debug("开始初始化系统常量缓存(SYS_CONSTS)======" + DateUtils.getCurTimestamp());
FINConstants.SYS_CONSTS = new HashMap<String, List<TFpsBaseConf>>();
List<TFpsBaseConf> confs = baseConfService.list();
if (confs != null) {
for (TFpsBaseConf conf : confs) {
List<TFpsBaseConf> confCaches = FINConstants.SYS_CONSTS.get(conf.getType());
if (confCaches == null) {
confCaches = new ArrayList<TFpsBaseConf>();
FINConstants.SYS_CONSTS.put(conf.getType(), confCaches);
}
confCaches.add(conf);
}
}
if (sysConstsBean != null && sysConstsBean.getConsts() != null) {
for (Map<String, String> cons : sysConstsBean.getConsts()) {
List<Map<String, Object>> conCdes = baseConfService.findOtherSysConsts(cons.get("type"),
cons.get("key"), cons.get("value"), cons.get("tableName"), cons.get("where"),
cons.get("orderby"));
for (Map<String, Object> conCde : conCdes) {
List<TFpsBaseConf> cdeCaches = FINConstants.SYS_CONSTS.get(cons.get("type"));
if (cdeCaches == null) {
cdeCaches = new ArrayList<TFpsBaseConf>();
FINConstants.SYS_CONSTS.put(cons.get("type"), cdeCaches);
}
TFpsBaseConf tFpsBaseConf = new TFpsBaseConf();
tFpsBaseConf.setType(conCde.get("TYPE").toString());
tFpsBaseConf.setKey(conCde.get("KEY").toString());
tFpsBaseConf.setValue(conCde.get("VALUE").toString());
cdeCaches.add(tFpsBaseConf);
}
}
}
}
}