java - <form :input > to map with object attribute in spring 中路径的动态值

标签 java spring spring-mvc

我想通过创建动态字符串来访问模型类变量。 下面是代码片段。

<form:input path="${accountType.field}.name.firstName" />

所需的输出为:direct.name.firstNameindirect.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/

相关文章:

java - Spring MVC 自定义转换器不工作

java - Swing 自定义边框

java - 不同的 Spring 配置文件适用于不同的构建

spring-mvc - 从 web.xml 中的过滤器映射中排除 url

java - 无法在 Log4j Spring 桌面应用程序中记录 java.sql.SQLException

java - REST 调用减慢了 Spring Boot 应用程序的速度 - 需要改进性能

java - 我需要一个服务对象吗?

java - 在 HijrahChronology 中配置自定义变体以进行日期校正 jdk 8

java - Tomcat org.apache.catalina.connector.requestfacade.getsession()占用CPU资源超过44.7%

java - getCanonicalPath 和 toRealPath 之间的区别