我开发了一个带有春季框架和其他一些框架的 MVC 应用程序( 我是一个初学者 ) 。 我有一个控制器来管理jsp 处理, 例如当我想在个人列表中添加新人时, 我调用一个瞬间化个人对象, 并将其传送到与添加方法相应的jsp 视图 。 我这样做的方法是这样的:
@RequestMapping(value = "/persons/add", method = RequestMethod.GET)
public String getAdd(Model model) {
logger.debug("Received request to show add page");
// Create new UserDomain and add to model
// This is the formBackingOBject
model.addAttribute("personAttribute", new UserDomain());
// This will resolve to /WEB-INF/jsp/addpage.jsp
return "addpage-tiles";
}
My problem is that now, I want to pass to add to the model two different Objects, for example, I want to pass the new UserDomain() and also an other object which is from an other table in my database, for example a new UserSecurity() . I think I should use a modelMap instead of the model.addAttribute... , but I can t do this, so if someone could help me. I get my model from the jsp by a code like :
<form:form modelAttribute="personAttribute" method="POST" action="${saveUrl}">
<table>
<tr>
<td><form:label path="firstName">First Name:</form:label></td>
<td><form:input path="firstName"/></td>
</tr>
<tr>
<td><form:label path="lastName">Last Name</form:label></td>
<td><form:input path="lastName"/></td>
</tr>
<tr>
<td><form:label path="userName">User name</form:label></td>
<td><form:input path="userName"/></td>
</tr>
<tr>
<td><form:label path="email">E-mail</form:label></td>
<td><form:input path="email"/></td>
</tr>
</table>
<input type="submit" value="Save" />
非常感谢你帮我