英文:
Thymeleaf th:field in textarea not working
问题
我在几种语言中有一段描述,使用Thymeleaf时,我发现textarea中的th:field不起作用!
与此同时,input中的th:text或th:value起作用,并在POST请求时更新数据。
请帮助我找出原因
<label>描述</label>
<textarea id="description" th:field="*{description}" placeholder="输入内容">
</textarea>
// 这个有效,但我需要使用<textarea>
<input type="text" th:value="${description}" th:name="description"/>
// 控制器
@GetMapping("/{language}/post/{id}/edit")
public String editPost(@PathVariable Language language,
@PathVariable Long id,
Model model) throws Exception {
model.addAttribute("post", postService.getPost(id));
model.addAttribute("language", language.getCode());
String description = postService.getDescription(id, language);
model.addAttribute("description", description);
return "admin/post-edit";
}
尝试了不同的选项 - 没有帮助(((
英文:
I have a description in several languages, using thymeleaf I came across the fact that th:field in textarea not working!
At the same time th:text or th:value in input works and updates the data on POST request.
Please help me find the cause
<label>Description</label>
<textarea id="description" th:field="*{description}" placeholder="Enter content">
</textarea>
//This works, but I need to use "textarea"
<input type="text" th:value="${description}" th:name="description"/>
//Controller
@GetMapping("/{language}/post/{id}/edit")
public String editPost(@PathVariable Language language,
@PathVariable Long id,
Model model) throws Exception {
model.addAttribute("post", postService.getPost(id));
model.addAttribute("language", language.getCode());
String description = postService.getDescription(id, language);
model.addAttribute("description", description);
return "admin/post-edit";
}
Tried different options - nothing helps (((
答案1
得分: 1
你可以使用 `th:text` 来设置 `<textarea>` 的内容:
<details>
<summary>英文:</summary>
You can use `th:text` to set the content of the `<textarea>`:
<textarea id="description" th:name="description" th:text="${description}"
placeholder="Enter content"></textarea>
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论