Thymeleaf自动生成表单 [英] Thymeleaf automatic form generation

查看:955
本文介绍了Thymeleaf自动生成表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想以特定的方式创建表单。应该像这样使用表单:

I'd like to create form in specific way. The form should be able to render itself based on received data, should be used like that:

 <form action="#" th:action="@{/blahblah}" th:formDefinition="${formDef}" th:object="${formData}"method="post">

这应该以某种方式呈现必要的输入元素,填入数据等。有没有办法如何在Thymeleaf中实现这一点?

This should render the necessary input elements in some way, fill in the data etc. Is there a way how to achieve this in Thymeleaf?

推荐答案

纯粹 thymeleaf c $ c>你可以这样做。

Nope there is no such way in pure thymeleaf which you can do this.

但您可以选择使用片段完成此类操作。

But you have an option to do something like this using fragments.


  1. 创建一个 th:fragment ,它带有参数 formDef formData

  2. 在片段中,根据需要动态
  3. 创建一个循环并创建表单。 >
  4. 在需要生成表单的地方使用 th:include 与真实参数调用片段。

  1. Create a th:fragment which takes the parameters formDef and formData
  2. In the fragment, create a loop and geenrate the form as you want dynamically
  3. Call the fragment using th:include with the real parameters in the places where you need the form to get generated.

这篇关于Thymeleaf自动生成表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆