代码之家  ›  专栏  ›  技术社区  ›  stephan

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

  •  1
  • stephan  · 技术社区  · 7 年前

    我正在将thymeleaf用于我的web应用程序。保存和更新函数存在问题。当我想从ui保存活动时,活动对象字段在rest控制器类中为空。这个问题只发生在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字段更改为value like this 邮递但问题仍然存在。

    <input type="hidden" th:value="*{id}"/>
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   mns45    7 年前

    您的表单类型为 "multipart/form-data" . 所以你必须加上 spring.http.encoding.enabled=false 应用程序。属性。

        2
  •  0
  •   Antoniossss    7 年前

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