Map 中的 Spring 绑定值 [英] Spring binding values in a Map

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

问题描述

有没有办法在地图中绑定值?

Is there a way to Spring bind values in a map?

例如,我有一个 Map 并且我想在其中绑定特定的值.用户将在 input 元素中键入一些内容,该 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.

推荐答案

是的,您可以使用 [...] 语法来完成.然而,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 = ...;
    ...
}

然后您提交一个表单,输入字段名为 values['foo'],即使用 Spring 表单标签,它将是一个 path:

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 中的

name:

or name in plain HTML:

<input name = "values['foo']" type = "text" />

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

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