Thymeleaf中textarea中的th:field不起作用。

huangapple go评论96阅读模式
英文:

Thymeleaf th:field in textarea not working

问题

我在几种语言中有一段描述,使用Thymeleaf时,我发现textarea中的th:field不起作用!

与此同时,input中的th:text或th:value起作用,并在POST请求时更新数据。

请帮助我找出原因

  1. <label>描述</label>
  2. <textarea id="description" th:field="*{description}" placeholder="输入内容">
  3. </textarea>
  4. // 这个有效,但我需要使用<textarea>
  5. <input type="text" th:value="${description}" th:name="description"/>
  6. // 控制器
  7. @GetMapping("/{language}/post/{id}/edit")
  8. public String editPost(@PathVariable Language language,
  9. @PathVariable Long id,
  10. Model model) throws Exception {
  11. model.addAttribute("post", postService.getPost(id));
  12. model.addAttribute("language", language.getCode());
  13. String description = postService.getDescription(id, language);
  14. model.addAttribute("description", description);
  15. return "admin/post-edit";
  16. }

尝试了不同的选项 - 没有帮助(((

英文:

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

enter image description here

  1. &lt;label&gt;Description&lt;/label&gt;
  2. &lt;textarea id=&quot;description&quot; th:field=&quot;*{description}&quot; placeholder=&quot;Enter content&quot;&gt;
  3. &lt;/textarea&gt;
  4. //This works, but I need to use &quot;textarea&quot;
  5. &lt;input type=&quot;text&quot; th:value=&quot;${description}&quot; th:name=&quot;description&quot;/&gt;
  6. //Controller
  7. @GetMapping(&quot;/{language}/post/{id}/edit&quot;)
  8. public String editPost(@PathVariable Language language,
  9. @PathVariable Long id,
  10. Model model) throws Exception {
  11. model.addAttribute(&quot;post&quot;, postService.getPost(id));
  12. model.addAttribute(&quot;language&quot;, language.getCode());
  13. String description = postService.getDescription(id, language);
  14. model.addAttribute(&quot;description&quot;, description);
  15. return &quot;admin/post-edit&quot;;
  16. }

Tried different options - nothing helps (((

答案1

得分: 1

  1. 你可以使用 `th:text` 来设置 `<textarea>` 的内容:

  1. <details>
  2. <summary>英文:</summary>
  3. You can use `th:text` to set the content of the `&lt;textarea&gt;`:

<textarea id="description" th:name="description" th:text="${description}"
placeholder="Enter content"></textarea>

  1. </details>

huangapple
  • 本文由 发表于 2023年3月23日 09:58:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818695.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定