Thymeleaf自动生成表单 [英] Thymeleaf automatic form generation
本文介绍了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.
- 创建一个
th:fragment
,它带有参数formDef
和formData
- 在片段中,根据需要
动态 创建一个循环并创建表单。 > - 在需要生成表单的地方使用
th:include
与真实参数调用片段。
- Create a
th:fragment
which takes the parametersformDef
andformData
- In the fragment, create a loop and geenrate the form as you want
dynamically
- Call the fragment using
th:include
with the real parameters in the places where you need the form to get generated.
这篇关于Thymeleaf自动生成表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文