在Spring MVC中绑定地图 [英] Bind Map in spring mvc

查看:68
本文介绍了在Spring MVC中绑定地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在spring mvc 2中有一个表单,其命令类为"Class1"

I have a form in spring mvc 2 having command class "Class1"

我想将Class3元素与这种形式的输入字段绑定.下面是我的课程.

I want to bind Class3 elements with an input field in this form. Below are my classes.

我正在迭代/绑定JSP中的Class2元素,而不是像这样的映射

I am iterating/binding over Class2 elements in JSP other than map like this

<c:forEach var="item" items="${class1.class2List}" varStatus="itemsRow">  
    <form:input path="class2List[${itemsRow.index}].anyElement2" />
    ..........
</c:forEach>

我的课程看起来像

Class1
List<Class2> class2List;
String anyElement1;

Class2
Map<String, Class3> class2Map;
String anyElement2;

Class3
Map<String, Class3> class3Map;
String nameToGet;
String anyElement3;

如何在class3Map内绑定anyElement3.有可能吗?

How can I bind anyElement3 inside class3Map. Is it possible?

针对第一个答案进行了编辑

Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property 'class2List[0].class2Map[0]' of bean class [com.Class1]: Could not instantiate property type [com.Class3] to auto-grow nested property path: java.lang.InstantiationException: com.Class3
    at org.springframework.beans.BeanWrapperImpl.newValue(BeanWrapperImpl.java:641)

推荐答案

假设您的class2Map有一个带有键的条目,例如mapkey,请尝试以下操作:

Assuming your class2Map has an entry with key, say, mapkey, try this:

<form:input path="class2List[${itemsRow.index}].class2Map['mapkey'].anyElement3" />

这篇关于在Spring MVC中绑定地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆