我有一个简单的 HTML 表单:
<form id="marketplaceForm" enctype="multipart/form-data" method="post">
<select name="category">
<option selected ></option>
<option value="Sales">Sales</option>
<option value="Marketing" >Marketing</option>
</select>
<textarea type="text" id="marketplaceDesc" name="description" value="" class="creattbleArea"></textarea>
<input type="text" id="marketplaceName" name="templateName" >
<input type="file" id="marketplaceLogo" name="logo">
<input type="submit" value="Save" id="update" />
<input type="text" id="marketplacePrice" name="price">
</form>
我需要在提交时自动绑定(bind)此表单。这工作正常:
@RequestMapping(value = "/.....", method = RequestMethod.POST)
public String PublishForm() {
但这会引发以下错误:
HTTP 状态 400 - 客户端发送的请求在语法上不正确
@RequestMapping(value = "/PublishApplication.htm", method = RequestMethod.POST)
public String PublishForm(@RequestParam("templateName") String templateName,
@RequestParam("category") String category,
@RequestParam("price") String price,
@RequestParam("description") String description
) {
谁能帮帮我吗?
更新:我发现,如果我从 HTML 表单中删除 enctype="multipart/form-data"
,它就会起作用。现在我的问题是如何使其与 enctype="multipart/form-data"
一起使用。
最佳答案
我认为您的配置中可能缺少多部分解析器。
你的配置中有类似的东西吗?
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="250000"/>
</bean>
参见here有关此事的官方 spring 文档。
关于java - Spring MVC 3 表单绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7525482/