Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 包含API和Web表单的呈现模板_Spring_Thymeleaf - Fatal编程技术网

Spring 包含API和Web表单的呈现模板

Spring 包含API和Web表单的呈现模板,spring,thymeleaf,Spring,Thymeleaf,我在页面上包含以下表单模板: <th:block th:fragment="barcodeForm"> <form th:action="@{/labels/barcodes}" method="post" th:object="${newBarcode}"> <th:block th:replace="forms/fields/inputs::input(

我在页面上包含以下表单模板:

<th:block th:fragment="barcodeForm">
    <form th:action="@{/labels/barcodes}" method="post" th:object="${newBarcode}">
      <th:block th:replace="forms/fields/inputs::input(fieldName='code')"/>
      <th:block th:replace="forms/fields/inputs::submit(text='Save')"/>
    </form>
</th:block>

这代表一个实体,但我有许多类似的片段。一些实体具有多对多关系,我想为这些实体创建一个内联表单。表单将通过ajax加载到相关实体的表单中,然后通过ajax提交,新ID将设置为隐藏输入

我试图实现的是从后端呈现表单并以JSON格式发送,这样我就可以拥有一个包含实体表单的文件。问题是,正如我所发现的,当不在适当的Thymeleaf上下文中时,我不能使用
th:object
和其他与表单相关的奇特属性

在呈现表单以便在JSON中发送时能够忽略这些属性的最佳方式是什么?在我看来,它们不仅不工作,而且还会抛出异常

编辑:

说清楚。我更感兴趣的是呈现html,而不是拥有模型属性的功能。我希望将其保留在web部件中,但如果需要,我可以在api中手动处理提交