2016-05-16 163 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}"/>