使用春天百里香叶访问文本区域

access textarea with spring-thymeleaf

本文关键字:访问 文本 区域 春天 百里香 叶访问      更新时间:2023-09-26

以下问题:我尝试更改文本区域的文本。
我正在使用Sping和Thymeleaf。
现在我的代码看起来像这样:

春天:

    [...]
    modelMap.addAttribute("Email", "035and so on");
    modelMap.addAttribute("Notes", "Please take this text and use it!");
    [...]

百里香叶:

    [...]
    <div class="col-sm-6 col-md-6 col-lg-6">
        <input name="Tel" class="form-control" placeholder="Telefonnummer"
        th:value="${Tel}" style="width: 100%;" />
    </div>
    <div><textarea class="form-control" rows="12"
        style="margin-top: 10px;"  placeholder="Sonstige Bemerkungen"
        name="notes" th:field="*{Notes}">
    </textarea></div>
    [...]

电话字符串工作正常,但我不知道如何访问
文本区域。如果有人能帮助我,会很高兴。

我在发现文本区域不支持值属性时遇到了同样的问题。如果您尝试将 thymeleaf 变量插入 html 文本区域,则可以使用文本内联。 所以像这样的事情...

<div><textarea class="form-control" rows="12"
    style="margin-top: 10px;"  placeholder="Sonstige Bemerkungen"
    name="notes" th:inline="text">[[${Notes}]]
</textarea></div>

很好的参考:http://loongest.com/uncategorized/thymeleaf/

你可以只使用th:text它也可以工作。我更喜欢@Amy的方式。

我遇到了同样的问题,你可以试试 th:text,它对我有用。

th:text="${Notes}"