0

我有地图<String, Object>:

params={
  dateOfBirthTo=23.05.2013,
  lastName=bbb, ssn=aa-ccc-ddd,
  gender=MALE,
  dateOfBirthFrom=03.05.2013,
  firstName=aaa
}

然后我有一个包含这张地图变量的表格。如何通过反射创建具有此值的新形式?

就像是:

SimpleForm form = new SimpleForm();

Map<String, Object> parameters = request.getParams();
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
  // fill form
}
4

1 回答 1

0

你可以使用Apache Commons BeanUtils

SimpleForm form = new SimpleForm();

Map<String, Object> parameters = request.getParams();
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
    BeanUtils.setProperty(form, entry.getKey(), entry.getValue());
}
于 2013-05-21T11:22:56.940 回答