Java Spring:访问JSP下拉列表中的模型属性列表

Java Spring:访问JSP下拉列表中的模型属性列表,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,从我的控制器,我向我的jsp视图发送一个对象列表。我正在使用springform:selecttag来创建一个下拉列表,它显示了内存中的奇怪对象引用。如何让它只显示我传入的对象的名称属性 <form:form commandName="game"> <form:select path="name" items="${listOfGames}"></form:select> </form:form> 此代码为我提供

从我的控制器,我向我的jsp视图发送一个对象列表。我正在使用springform:selecttag来创建一个下拉列表,它显示了内存中的奇怪对象引用。如何让它只显示我传入的对象的名称属性

    <form:form commandName="game">
       <form:select path="name" items="${listOfGames}"></form:select>
    </form:form>


此代码为我提供了一个游戏对象下拉列表,但我希望该下拉列表显示名称属性

我猜问题在于您没有使用选项标签

<form:form commandName="game">
   <form:select path="name"> 
       <form:options items="${listOfGames}" />
   </form:select>
</form:form>

我猜问题在于您没有使用选项标签

<form:form commandName="game">
   <form:select path="name"> 
       <form:options items="${listOfGames}" />
   </form:select>
</form:form>

试试这个::

<form:form method="post" commandName="game">
<form:select path="name">
<form:option label="Setect A Game"/>
<form:options items="${listOfGames}"/>
</form:select> 
</form:form>

试试这个::

<form:form method="post" commandName="game">
<form:select path="name">
<form:option label="Setect A Game"/>
<form:options items="${listOfGames}"/>
</form:select> 
</form:form>

如果您只是像上面那样使用items属性,spring将尝试“字符串化”您的列表/数组元素,即在每个元素中调用toString(),因为您没有覆盖它,所以在Object中定义的元素。例外情况是,只要您传递一个
映射,其中键用于值属性和要显示的值

您必须正确使用form:options标记来显式声明哪个属性用于键,哪个属性用于显示

<form:select path="game">
    <form:options items="${listOfGames}" itemValue="id" itemLabel="name"/>
</form:select>


假设您想绑定id属性,如果您只是使用上面的items属性,spring将尝试“字符串化”列表/数组元素,即在每个元素中调用toString(),因为您没有覆盖它,所以在Object中定义的元素。例外情况是,只要您传递一个
映射,其中键用于值属性和要显示的值

您必须正确使用form:options标记来显式声明哪个属性用于键,哪个属性用于显示

<form:select path="game">
    <form:options items="${listOfGames}" itemValue="id" itemLabel="name"/>
</form:select>


假设您想要绑定id属性,您可以使用MaplistOfGames。这样,您就可以在上面写的时候使用表单了。listOfGames的值部分必须是对象的名称属性。您可以使用MaplistOfGames。这样,您就可以在上面写的时候使用表单了。listOfGames的值部分必须是对象的名称属性。请在回答中添加一些说明,说明代码如何解决此问题。这将有助于将来看到您答案的其他人请在您的答案中添加一些说明,说明您的代码是如何解决问题的。这将有助于其他人在未来看到你的答案真棒,itemLabel是我需要让它工作的东西。非常感谢。太棒了,itemLabel是我工作所需要的。非常感谢。