0
我正在處理兩個有多對多關係的類。我在兩個表中插入數據,關係通常在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>
現在缺少的是能夠顯示來自兩個表中的數據? 謝謝。