感谢您的回复。
但不是吗:(
我有一个表格,其中数据将被持久保存在两个不同的表中。
<form class="form-signin" method="post" action="addAgency">
<div class="input-group">
<span class="input-group-addon entypo-user"></span>
//Table Agency
<spring:bind path="tenant.firstName"/>
<input class="form-control" placeholder="Nome"/>
//Table Login
<spring:bind path="login.email"/>
<input class="form-control" placeholder="Nome"/>
</div>
//Rest of my form...
</form>
在我看来,我有注释“绑定”Spring,在互联网上搜索我发现这种方式可以在控制器和视图之间建立连接以持久化两个表。
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(@ModelAttribute("tenant") Agency tenant, @ModelAttribute("login") Login login, ModelMap map) {
Agency agency = dashboardFacade.getAgency();
map.addAttribute("agency", agency);
if (tenantResolver.isMasterTenant()) {
//Here is the problem!!
// Add an attribute in my view of type login and agency, but i don't kwon if it is correct.
map.addAttribute("tenant", tenant);
map.addAttribute("login", login);
return "landing/index";
} else {
return "dashboard/home";
}
}
以下方法保存代理并登录。
// Add a new agency
@RequestMapping(value = "/addAgency", method = RequestMethod.POST)
public String addAgency(@ModelAttribute("tenant") Agency agency, @ModelAttribute("login") Login login, Model model, final RedirectAttributes redirectAttributes) {
agency = dashboardFacade.addAgency(agency);
login = dashboardFacade.addLogin(login);
return "redirect:" + getAgencyFullUrl(agency);
}
有什么更好的方法来做到这一点?
谢谢