public class DicMap {
@Autowired
private static CustomerDao customerDao;
private static HashMap<String,String> hashMap=new HashMap<>();
static {
//在这里我们不能使用注入进来的customerDao,因为它此时还没有被创建出来,所以我们要在系统
//运行的时候获取项目的上下文手动去获取这个bean
customerDao = SpringUtil.getBean(CustomerDao.class);
queryDic();
}
//把字典信息放到map中
public static void queryDic(){
List<Dictionary> dics=customerDao.findAllDictionary();
for (int i = 0; i < dics.size(); i++) {
Dictionary dic = dics.get(i);
String divi = dic.getDivi();
Integer code = dic.getCode();
String value = dic.getVal();
String key=divi+code;
hashMap.put(key,value);
}
}
//获取字典信息的具体方法
public static String getDicVal(String divi,Integer code){
String key=divi+code;
String
springboot在项目启动时加载字典表数据进map内存,真实测试通过。
最新推荐文章于 2025-03-24 10:05:17 发布