2013-08-22 55 views
0

我在春天3 mvc有webapp。這種情況是我有索引頁面的網址,當用戶點擊他們應該顯示另一個頁面的細節選擇的信息。現在顯示詳細信息頁面,但沒有任何信息(在索引頁面上正在創建具有正確變量的模型,但未詳細說明控制器 - 在調試模式下)。 指數控制方法:春天mvc映射 - 發送控制器之間的值

@RequestMapping(value="/{site}", method = RequestMethod.GET) 
public String showDetails(@RequestParam(value = "site", required = true) String site, Model model){ 
    Catalog product = catalogEndpoint.getByTitle(site); 
    model.addAttribute("product", product); 
    return "details"; 
    } 

指數HTML:

<form action="#" th:object="${product}" method="post" th:action="@{/details}"> 
    <table border="0" width="600" th:each="sb, poz : ${product}" > 
<tr > 
<td rowspan="3" width="20"><span th:text="${poz.count}"></span></td> 
<td> 
<a th:href="@{/details/(site=${sb.tytul})}" th:value="${site}"><span th:text="${sb.tytul}"></span></a> 
    </td> 
    </tr> 
    <tr > 
<td><span th:text="${sb.adres}"></span></td> 
</tr> 
<tr> 
<td>category:<b><span th:text="${sb.category.name}"></span></b></td> 
    </tr> 
    </table> 
    </form> 

細節控制器的方法:

@RequestMapping(value = "details/{site}", method = RequestMethod.GET) 
public String showHomePage(@PathVariable(value = "site") String site, Model model){ 
    model.addAttribute("product"); 
    return "details"; 
} 

細節HTML:

<form th:object="${product}" method="get" th:action="@{/details}"> 
    <table border="1" width="600" > 
<tr > 
<td ><span th:text="${tytul}"></span></td> 
<td> 
<span th:text="${opis}"></span> 
    </td> 
<td><span th:text="${adres}"></span></td> 
</tr> 
</table> 
</form> 

我沒有任何想法如何馬詳細的網站(我嘗試了很多解決方案,但沒有)。感謝幫助。

+0

用百里香,這個「@ {/ details /(site = $ {sb.tytul})}}」評估爲,例如。通過'http://yourhost.com/context/details網站= tytul'。你的控制器是否映射到那個? –

+0

是的控制器映射OK。 – user978758

回答

1

隨着thymeleaf,使用th:object,你需要*{}

<form th:object="${product}" method="get" th:action="@{/details}"> 
    <table border="1" width="600" > 
<tr > 
<td ><span th:text="*{tytul}"></span></td> 
<td> 
<span th:text="*{opis}"></span> 
    </td> 
<td><span th:text="*{adres}"></span></td> 
</tr> 
</table> 
</form> 

假設tytulopis引用一個對象的字段,以及adresproduct領域。除非它是一個類型,不要忘記

Catalog product = catalogEndpoint.getByTitle(site); 
model.addAttribute("product", product); 
details控制器的方法

,否則你不會有Catalog模型屬性。

+0

完美的作品,謝謝。 – user978758

0

在你的細節控制器裏你在哪裏設置產品對象在你的模型?

model.addAttribute("product"); 

只是settingstring對象的 「產品」,獲取產品對象,並將其設置在細節控制器就像你在showDetails方法做了

+0

感謝您的建議,我解決了它。 – user978758

0

變化

model.addAttribute("product"); 

Catalog product = catalogEndpoint.getByTitle(site); 
model.addAttribute("product", product); 
「showPage」方法中的

+0

謝謝,此後改變了作品。 – user978758