0
在春季開機誰接收後模型,並在同一時間發送變量到百里香模板?如何從同一控制器發送變量並同時接收模型?
@Controller
public class ProfilingController {
@GetMapping("/")
public String main(Model model){
FormModel form_model = new FormModel();
model.addAttribute("form_model", form_model);
model.addAttribute("demo", "abc");
return "main_template";
}
@PostMapping("/")
public String receive(@ModelAttribute ModelForm form_model){
FormModel form_model = new FormModel();
// How to set model to send the var to thymeleaf template?
model.addAttribute("form_model", form_model);
model.addAttribute("demo", "abc");
return "main_template";
}
}
如果POST方法receibe模型,如何設置模型送瓦爾到模板?如果發送兩個參數不工作:
@PostMapping("/")
public String receive(Model model, @ModelAttribute ModelForm form_model){
的model_form是空的。
模板:
<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
</head>
<body>
<form class="form-signin" action="#" method="post" th:action="@{/}" th:object="${form_model}">
<input th:field="*{email}" required="required" type="email" />
<input th:field="*{password}" type="password" />
<p th:text="${demo}"></p>
<button type="submit">Submit</button>
</form>
</body>
</html>
,嘗試添加一個以上可變'ModelMap model',添加所需的屬性,以'model'對象.. –
的模型對象工作正常,但在form_model是空:( –
可以你提供了'FormModel'的基本代碼,你有getters/setter嗎?同樣,你正在創建一個空對象(我假設,因爲使用默認構造函數FormMode()') –