1、代码模式
public class ApplicationContext {
private Map<String, Object> container = new HashMap<String, Object>();
@SuppressWarnings("unchecked")
public <C> C get(String key, Class<C> c){
try {
return (C)container.get(key);
} catch (Exception e) {
return null;
}
};
public boolean put(String key, Object o){
container.put(key, o);
return true;
}
}
调用的put和get方法分别如下:
applicationContext.put("classAffectDto", classAffectDto);
ADto aDto = applicationContext.get("aDto", ADto.class);