0

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

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

但是我无法将 a 映射ColumnConfig到地图条目的value属性。questionResponses例如,我想要这样的东西:

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

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

4

1 回答 1

1

一种解决方案是使用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);
    }

}
于 2013-05-29T15:08:06.133 回答