Which Thymeleaf attribute is used to set the value of an input field?

Which Thymeleaf attribute is used to set the value of an input field?

A) th:value
B) th:text
C) th:field
D) th:data

Answer:

A) th:value

Explanation:

The th:value attribute in Thymeleaf is used to set the value of an input field dynamically. This attribute binds the value of the input field to a model attribute, making it easy to populate forms with existing data.

For example:


<input type="text" th:value="${user.name}" />

In this example, the th:value attribute sets the value of the input field to the name property of the user object.

Reference links:

https://www.javaguides.net/p/thymeleaf-tutorial.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top