【发布时间】:2016-06-16 09:31:19
【问题描述】:
我正在制作一个 Spring MVC 项目,我的 .jsp 中有这个表单
JSP
<form:form action="/admin/assign/add" modelAttribute="cafeTable">
<table>
<tr>
<td>
<form:label path="tableNumber">
<spring:message text="Table's Number"/>
</form:label>
</td>
<td>
<form:select path="tableNumber" action = "select">
<form:options items="${tableNumbers}"></form:options>
</form:select>
</td>
</tr>
<tr>
<td>
<form:label path="${user.fullName}">
<spring:message text="Waiter's name"/>
</form:label>
</td>
<td>
<form:select path="${user.fullName}" action = "select">
<c:forEach items="${listUser}" var="user">
<option value="${user.fullName}">${user.fullName}</option>
</c:forEach>
</form:select>
</td>
</tr>
</table>
<br>
<input type="submit" name="assign"
value="<spring:message text="Assign"/>"/>
</form:form>
所以我有User 和CafeTable 模型,但我的模型属性是CafeTable。
使用提交按钮,我需要在我的控制器中获取两个选定的值:
@RequestMapping(value = "/admin/assign/add", params = "assign", method = RequestMethod.POST)
public String assign(@ModelAttribute("cafeTable") CafeTable cafeTable) {
//set cafeTable's UserID field matching selected fullName value
tableService.addTable(cafeTable);
return "admin";
}
我该怎么做?
【问题讨论】:
-
目前你得到的值是多少? CafeTable 应该包含 tableNumber 属性,并且应该填充值
-
是的,CafeTable 确实包含 tableNumber,但我还需要获取用户 ID(通过获取用户的全名),以便我可以设置 CafeTable 的 UserID 字段。
标签: java jsp spring-mvc