2016-03-06 93 views
0

我正尝试使用springMvc和thymeleaf创建编辑表单。输入字段没有使用从控制器返回的值填充。输入字段在Thymeleaf Spring MVC中显示为空白

控制器:

@RequestMapping(value = "updatecustomer") 
public String search(@ModelAttribute("customerDto") CustomerDto customerDto, Model model) { 
    Customer customer = service.search(customerDto); 
    model.addAttribute("customer", customer); 
    return "mypage"; 
} 

形式:

<input type="text" id="email" name="email" value=""> 

调试示出的值是存在于控制器并返回到查看但电子邮件输入:在浏览器

<form method="post" th:action="@{updatecustomer}" th:object="${customerDto}"> 
    <label>Email: </label><input type="text" th:field="*{email}" /> 
    <input type="submit" /> 
</form> 

生成html值为空白。

请指教。

回答

1

在你Thymeleaf代码你customerDto结合的形式

th:object="${customerDto}" 

凡在你的控制器,你是路过的客户数据客户属性名称

model.addAttribute("customer", customer); 

你应该使这些二。例如,将您的Thymeleaf代码更改为此

th:object="${customer}" 
0

也许您应该在您的JSP中映射模型中的实体“客户”,并使用它自己的字段!

<label>Email: </label><input type="text" th:field="*{customer.email}" /> 

试试吧,告诉我们!