gpt4 book ai didi

java - GXT如何获取BeanModel的Map属性

转载 作者:行者123 更新时间:2023-12-01 14:32:55 25 4
gpt4 key购买 nike

我有一个 DTO,它看起来有点像这样:

class Response {
Long id;
Locale locale;
Map<Integer,QuestionResponse> questionResponses=new HashMap<Integer,QuestionResponse>();
...
}

但我在将 ColumnConfig 映射到 questionResponses 映射条目的 value 属性时遇到问题。例如,我想要这样的东西:

beanModel.get("questionResponses[15].value")

我可以从 BeanModelData 中的 get 方法看出,我应该能够获取 Map 的属性,但无法弄清楚语法。任何帮助将不胜感激。

最佳答案

一种解决方案是使用 DataReader将您的响应映​​射到新模型

final ListLoader<BaseListLoadResult<BeanModel>> loader = new BaseListLoader<BaseListLoadResult<BeanModel>>(
proxy, new MyBeanModelReader());
loader.load();
new ListStore<BeanModel>(loader); //TODO

public class MyBeanModelReader implements DataReader<List<BeanModel>> {

private BeanModelReader reader = new BeanModelReader();

public boolean isFactoryForEachBean() {
return reader.isFactoryForEachBean();
}

public List<BeanModel> read(Object loadConfig, Object data) {
List<BeanModel> newModelsData = new ArrayList<BeanModel>();
ListLoadResult<ModelData> models = reader.read(loadConfig, data);
List<ModelData> modelsData = models.getData();
for (ModelData modelData : modelsData) {
BeanModel model = (BeanModel) modelData;
Response response = (Response) model.getBean();
model.set("id", response.getId());
model.set("locale", response.getLocale());
model.set("QuestionResponse15", response.getQuestionResponse().get(...)); //retrieve the QR you want
newModelsData.add(model);
}
return newModelsData;
}

public void setFactoryForEachBean(boolean factoryForEachBean) {
reader.setFactoryForEachBean(factoryForEachBean);
}

}

关于java - GXT如何获取BeanModel的Map属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16714806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com