Spring_ implementing form Binding with Thymeleaf

Source: Internet
Author: User

As long as the goal-specific and not half-hearted, perseverance and not halfway, we will be able to achieve our beautiful ideals.

Use Thymeleaf to bind a form to the object specified by Th:object.

<HTMLxmlns= "HTTP://WWW.W3.ORG/1999/XHMTL"xmlns:th= "http://www.thymeleaf.org"><Head><title>Register</title></Head><Body>    <formMethod= "POST"Th:object= "${user}">        <Divclass= "Errors"th:if= "${#fields. HasErrors (' * ')}">            <ul>                <LiTh:each= "ERR: ${#fields. Erros (' * ')}"Th:text= "${err}"                >Input is incorrect</Li>            </ul>        </Div>                <labelTh:class= "${#fields. HasErrors (' FirstName ')}? ' Error ' ">First Name</label>        <inputtype= "text"Th:field= "*{firstname}"Th:class= "${#fields. HasErrors (' FirstName ')}? ' Error ' "          />                  <labelTh:class= "${#fields. HasErrors (' LastName ')}? ' Error ' ">Last Name</label>        <inputtype= "text"Th:field= "*{lastname}"Th:class= "${#fields. HasErrors (' LastName ')}? ' Error ' "          />                       </form></Body></HTML>

 <th:field> Specifies the properties of the bound object.

Spring_ implementing form Binding with Thymeleaf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.