是否可以在表单的itemLabel中使用多个参数:select/form:option

kas*_*ega 18 spring jsp jstl spring-mvc

我正在使用Spring.我有一个带有表单的JSP:在其中选择显示用户列表.在这种情况下,用户名或ID对用户意义不大,因此我需要显示名字姓氏.

我试过了:

<form:select id="userSelect" name="userId" path="user.id">
    <option value="">Select to Edit</option>
    <form:options items="${user.userList}" itemValue="id" itemLabel="lastname firstname" />
</form:select>
Run Code Online (Sandbox Code Playgroud)

但这给了我一个很大的错误.如何让itemLabels显示姓氏,名字?

JB *_*zet 40

我不这么认为.getFullName()在对象中有一个getter返回last和first名称的串联,或者在循环中逐个显示选项:

<form:select id="userSelect" name="userId" path="user.id">
    <option value="">Select to Edit</option>
    <c:forEach var="theUser" items="${user.userList}">
        <form:option value="${theUser.id}"><c:out value="${theUser.lastname} ${theUser.firstname}"/></form:option>
    </c:forEach>
</form:select>
Run Code Online (Sandbox Code Playgroud)

连接由user.getFullName()以下各项执行:

<form:select path="user"
   items="${user.userList}"
   itemValue="id"
   itemLabel="fullName">
</form:select>
Run Code Online (Sandbox Code Playgroud)