首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何为Thymeleaf输入字段添加默认值?

如何为Thymeleaf输入字段添加默认值?
EN

Stack Overflow用户
提问于 2018-05-31 13:16:12
回答 1查看 1.1K关注 0票数 0

这是我的胸腺叶表单输入字段。我想为它设置一个默认值。假设我想要将“个人”设置为默认值。如何做到这一点?

 <div class="col-sm-9">
                            <label th:if="${#fields.hasErrors('priceSearchDTO.partyType')}" th:errors="*{priceSearchDTO.partyType}"
                                   class="validation-message"></label>
                            <input type="text" th:field="*{priceSearchDTO.partyType}" placeholder="partyType"
                                   class="form-control"/>
                        </div>

另外,我也尝试过这个,但它不能像普通的html字段那样工作。

<div class="col-sm-9">
                        <label th:if="${#fields.hasErrors('priceSearchDTO.partyType')}" th:errors="*{priceSearchDTO.partyType}"
                               class="validation-message"></label>
                        <input type="text" th:field="*{priceSearchDTO.partyType}" placeholder="partyType" value="individual"
                               class="form-control"/>
                    </div>
EN

回答 1

Stack Overflow用户

发布于 2018-05-31 18:01:23

有一个th:占位符属性。您可以使用此属性动态设置占位符属性的值,例如:

<input ...  th:placeholder="${#object.individualPlaceholder}" ...>

<input ...  th:placeholder="|Static and ${#object.dynamic}|" ...>

如果占位符是静态值,您仍然可以使用placeholder -属性:

<input ...  placeholder="Insert something" ...>

也可以对th:占位符使用静态值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50617087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档