我正在使用两个具有多对多关系的类。我在两个表中都插入数据,关系通常是在JoinTable中注册的。我的问题是,如何以相同的形式显示两个表中的数据?
这是我的控制器:
@Controller
public class RecipeController {
@Autowired
private ReceitaService receitaService;
@RequestMapping(value = "/novaReceita.do", method = RequestMethod.POST)
public String createRecipes(@ModelAttribute("Receita") Receita receita, BindingResult resultReceita,
@ModelAttribute("Tag") Tag tag, BindingResult resultTag, @RequestParam String action, Map<String, Object> map) {
receita.getTag().add(tag);
receitaService.addReceita(receita);
map.put("receita", receita);
map.put("receitaList", receitaService.getAllReceita());
return "listRecipes";
}
这是我遇到问题的地方,因为我只能显示单个表的数据。
public String editForm(@PathVariable("id") int id, ModelMap map) {
map.addAttribute("receita", receitaService.getReceita(id));
return "updateRecipes";
}
最后,JSP页面显示输入的数据:
<c:url var="url" value="/receita/${receita.id}"/>
<form:form action="${url}" method="GET" commandName="receita">
<table width=80% >
<tr>
<td><strong>ID </strong></td>
<td><form:input path="id" disabled="true" class="input-small"/></td>
</tr>
<tr>
<td><strong>Title </strong></td>
<td><form:input path="titulo" class="input-xlarge"/></td>
</tr>
<tr>
<td valign=top><strong>Desc probl</strong></td>
<td><form:textarea path="desc_prob" class="input-xlarge" rows="3" /></td>
</tr>
<tr>
<td valign=top><strong>Desc soluc</strong></td>
<td><form:textarea path="desc_soluc" class="input-xlarge" rows="6" /></td>
</tr>
<tr>
<td><strong>Tag</strong></td>
<td> <form:input path="tag" disabled="true" class="input-small"/></td>
</tr>
</table>
</form:form>
能够显示两个表中的数据缺少什么?谢谢。