2016-05-16 39 views
1

我正在從事此spring-boot項目,並且我正在從controller方法返回ModelAndView對象,我已將2個對象添加到ModelAndView。這部分工作,我想知道如何表示thymeleaf模板中的值。如何在thymeleaf模板內表示2個模型對象

public ModelAndView showEdit(@PathVariable int id,Customer cust,Model model){ 
    ModelAndView view = new ModelAndView(); 
    view.setViewName("editCustom"); 
    view.addObject("cust",cust); 
    view.addObject("log",login); 
} 

裏面的thymeleaf模板。

<form action="#" th:action="@{/save}" th:object="${cust}" method="post"> 
Name:<input type="text" th:field="*{name}" /> 

我可以獲取在cust值,但我不知道如何從login得到的值。 我試過這個,但它沒有working.note,所有的輸入標籤都在同一個表單中。

<input type="text" id="user" name="user" value="${login.uname}"/> 

回答

0

在模型中要添加的登錄信息作爲日誌,並在您的視圖您正在使用的登錄

view.addObject(「日誌」,登錄);

$ {login.uname}

此外thymeleaf使用一個屬性處理器,其處理與屬性第前綴。代替價值使用th:值如下

<input type="text" id="user" name="user" th:value="${log.uname}"/>