我想通过创建动态字符串来访问模型类变量。 下面是代码片段。
<form:input path="${accountType.field}.name.firstName" />
所需的输出为:direct.name.firstName
或 indirect.name.firstname
Account direct;
Account indirect;
这两个字段在模型中都可用。
我通过上述方法收到错误,似乎代码 ${accountType.field}
首先被编译并给出错误。
Error: Bean property ' ' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
如果我像这样编写硬代码值,它就可以完美工作。
<form:input path="direct.name.firstName" />
请建议我如何解决这个问题。
最佳答案
您可以使用名称值对而不是路径进行绑定(bind)。 使用
更改 html 元素<form id="myId">
<input name="${accountType.field}.name.firstName" value=""/>
</form>
并发布此表格
关于java - <form :input > to map with object attribute in spring 中路径的动态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26736258/