Thymeleaf 表单将带有空字段的对象发送到 weblogic 服务器中的控制器

Thymeleaf form send object with null fields to controller in weblogic server

我正在为我的 Web 应用程序使用 thymeleaf。保存和更新功能有问题。当我想保存来自 ui 的活动时,活动对象字段变为空以保留控制器 class。此问题仅发生在 weblogic server(12.1.3) 中。当我在 tomcat 服务器上尝试时,没有发生任何错误。

我的编辑和创建页面如下。竞选活动有几个领域,但我在这里写了一些。顺便说一下,我确信 html 页面中的所有字段都已准备就绪。有些是隐藏的,有些是可见的。

<div class="row">
    <form name="Form" class="col s8 offset-s2" id="upload-file-form"
          enctype="multipart/form-data" th:object="${campaign}"
          th:action="@{/admin/getCampaign}" onsubmit="return validateForm()"
          method="post">

        <div class="row">
            <input type="hidden" th:field="*{id}"/>
            <input type="hidden" th:field="*{version}"/>
        </div>
        <div class="row">
            <div class="input-field">
                <input id="brandname" type="text" class="validate" th:field="*{brandname}">
                <label for="brandname">Brand Name</label>
            </div>
        </div>
    </form>
</div>

@RequestMapping(value = "admin/getCampaign", method = RequestMethod.POST)
public String uploadingPost(@RequestParam("uploadingFiles") MultipartFile[] uploadingFiles,
                            @RequestParam("uploadingFiles1") MultipartFile[] uploadingFiles1,
                            @RequestParam("uploadingFiles2") MultipartFile[] uploadingFiles2,
                            @RequestParam("uploadingFiles3") MultipartFile[] uploadingFiles3,
                            Campaign campaign) throws IOException {

/** this is my controller method for save or update.
*/                                                              
}

in weblogic server campaign parameter fields come null (as a new object), but in tomcat server, everything is normal.

更新:

我将 ui 字段的值更改为 post。但问题依旧。

<input type="hidden" th:value="*{id}"/>

应该是<input type="hidden" th:field="*{id}"/>不是th:value

您的表单加密类型是 "multipart/form-data"。 所以你必须添加 spring.http.encoding.enabled=false 到 application.properties.