spring为表单添加默认值:select

Mik*_*ike 13 spring spring-mvc

我正在开发一个spring应用程序,现在我已经使用以下命令向我的一个jsp页面添加了一个下拉列表:

<form:select multiple="single" path="users[y.count-1].X" items="${Y}" itemValue="id" itemLabel="name"/>
Run Code Online (Sandbox Code Playgroud)

现在我想添加默认值"Nothing selected",但我似乎无法找到如何做到这一点.我试过了:

<form:select multiple="single" path="users[y.count-1].X" items="${Y}" itemValue="id" itemLabel="name">
   <form:option value="Nothing selected" />
</form:select>
Run Code Online (Sandbox Code Playgroud)

但是"我没有选择"没有显示在我的下拉列表中.

Jac*_*son 18

你应该能做到的

<form:select multiple="single" path="users[y.count-1].X" >
   <form:option value="Nothing selected" />
   <form:options items="${Y}"  itemValue="id" itemLabel="name" />
</form:select>
Run Code Online (Sandbox Code Playgroud)