@Component
public class ProgramId {
private static ProgramIdDao dao;
private static volatile List<ProgramIdWithMethodName> programIdList = null;
/**
*
* @param dao
*/
@Autowired
public ProgramId(ProgramIdDao dao) {
ProgramId.dao = dao;
}
/**
*
* @param methodName
* @return
*/
public static ProgramIdWithMethodName getProgramId(String methodName) {
if (programIdList == null) {
refreshProgramIdList();
}
for (ProgramIdWithMethodName info : programIdList) {
if (info.getMethodName().equals(methodName)) {
return info;
}
}
return null;
}
/**
*
*/
public static void refreshProgramIdList() {
synchronized (ProgramId.class) {
programIdList= dao.getProgramIdList().stream()
.map(ProgramIdListEntity::ProgramIdWithMethodName)
.collect(Collectors.toList());
}
}
}
spring 设置全局list变量,保存数据库只取一次的数据字典
最新推荐文章于 2021-10-25 21:58:58 发布