When should I use html's <form> and when

2019-01-26 10:00发布

问题:

I am wondering is it good practice to write all forms in spring tags or can I mix spring form tags with html form tags?

回答1:

Use Spring forms when you need functionality provided by them:

  • binding to objects
  • configurable field formatting
  • redisplay of values on errors
  • binding of error messages

For simple forms (such as a simple search box on each page) you usually don't need these features - therefore you can use simple HTML forms for them.



回答2:

Springs form:form tag is supposed to be used with whenever you have a formbacking object you wish to bind to the form (a model object delivered to your view).

There are no additional benefits of using the tag in a regular form with no backing object.