Spring MVC:通过路径属性将标记属性传递给控制器

Spring MVC: Pass tag attribute to the controller through path attribute

我正在使用 spring MVC 开发 Liferay portlet。 在视图部分,我有一个这样的下拉字段:

    <form:select path="addressUsage">
        <option>Home address</option>
        <option>Postal address</option>
    </form:select>

我们知道,在这种情况下,如果用户 select 例如第一个选项,那么视图将传递给控制器​​的值是 "Home address"(在相应 [ 的属性 addressUsage 中=32=]) 但我想要的是下拉列表显示 "Home address" 和 "Postal address" 选项,传递给控制器​​的是:

-> "HOME" 在用户 select "Home address" 选项的情况下。

-> "POSTAL" 在用户 select "Postal address" 选项的情况下

所以我想我在选项标签中添加了一个名称属性。所以下拉菜单将是这样的

    <form:select path="addressUsage">
        <option name="HOME">Home address</option>
        <option name="POSTAL">Postal address</option>
    </form:select>

所以我的问题是:是否可以通过路径属性传递相应selected选项的名称属性而不是选项文本?

我认为您要查找的是 value 属性。

<option value="HOME">Home address</option>,例如

您可以查看 here the value attribute of the option 标签的 定义和用法 -

The value attribute specifies the value to be sent to a server when a form is submitted.

The content between the opening and closing tags is what the browsers will display in a drop-down list. However, the value of the value attribute is what will be sent to the server when a form is submitted.

Note: If the value attribute is not specified, the content will be passed as a value instead.