春天在地图结合值 [英] Spring binding values in a Map
问题描述
有没有办法在地图中spring绑定值?
Is there a way to Spring bind values in a map?
比如说,我有一个地图<字符串,字符串>
,我想它去春来绑定特定的值。
用户将键入的东西到一个input元素,并输入元素的值将得到势必在地图上的特定键关联的值。
For instance, I have a Map<String,String>
and I want to spring bind specific values in it.
The user will type something into a input element, and the value of that input element will get bound to the value associated with a specific key in the map.
推荐答案
是的,你可以用 [...]
语法做到这一点。在地图
本身,但是,应该是命令对象的属性:
Yes, you can do it with [...]
syntax. The Map
itself, however, should be a property of the command object:
public class Form {
private Map<String, String> values = ...;
...
}
然后你提交一个表单与名为值['富']
,即使用Spring表单标签这将是一个路径输入字段
:
Then you submit a form with the input field named values['foo']
, i.e. with Spring form tags it would be a path
:
<form:input path = "values['foo']" />
或名称
在纯HTML:
<input name = "values['foo']" type = "text" />
这篇关于春天在地图结合值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!