我正在为表单上的文件上传而苦苦挣扎:用spring roo更新。
对于创建部分,我使用了Jose Delgado here提供的表单:多标签。定制的form:multi标签将enctype="multipart/ form -data“添加到表单中,这样做效果很好。
问题是当您想要为您的更新表单提供文件上传功能时。默认情况下,Spring Roo (可能是spring mvc,我不知道)会将应用程序“enctype=/x-www- form -urlencoded”设置为更新表单(form:update tag)。如果我在上传表单中将enctype属性设置为enctype="multipart/ form -data“,那么在提交表单时,服务器将执行控制器的"create”方法,而不是"udpate“方法……
你知道我们怎么才能(简单地)解决这个问题吗?我已经花了相当多的时间在它上面,我发现自己失去了灵感(也许是因为这是一天的末日,也是:)。
谢谢你的帮忙,
亲切的问候
发布于 2012-08-29 20:25:10
OK...It看起来RequestMapping有点小问题。
无论出于什么原因,当form:update标记中的multipart属性被设置为"true“时,方法参数就被设置为"POST”。
作为一种变通方法,我在create方法的开头检查了_method参数。如果设置为"PUT",我将返回update方法的值。
@RequestMapping(method = RequestMethod.POST, produces = "text/html")
public String create(@Valid ActionRequest actionRequest, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) {
// Work around dispatcher bug: if the multipart attribute of the form is set to true,
// submission of the update form routes to create method
String toto = httpServletRequest.getParameter("_method");
if(httpServletRequest.getParameter("_method").equals("PUT")){
return this.update(actionRequest,bindingResult,uiModel,httpServletRequest);
}
...
}https://stackoverflow.com/questions/12165164
复制相似问题