我使用的是springMvc+mybatis框架,想把数据库部分数据放到内存中,可mapper为空
private static Map<Integer, String> tables;
@Autowired
private static demoMapper mapper;
private static Demo me=null;
private Demo () {
}
public static Demo getInstance(){
if(me==null){
me=new Demo ();
tables = new HashMap<Integer, String>();
//从数据库全部取出
List<Map<String,Object>> lists=mapper.getConfig();
for(Map<String,Object> map:lists){
tables.put(Integer.valueOf(map.get("target").toString()), map.get("target_value").toString());
}
}
return me;
}
public String getTargetValue(int type){
String value = tables.get(target);
if(value == null){
//从数据库取出
//value =mapper.getValue ByTarget(target);
}
return value ;
}