[英]Neither BindingResult nor plain target object for bean name 'parametre'
I'm working with spring MVC, so Basically im creating a forum wich will take a file and radioButton as Input: form_li.jsp: 我正在使用Spring MVC,因此基本上,我在创建一个论坛时将文件和radioButton作为输入:form_li.jsp:
<f:form id="form1"
name="form1"
modelAttribute="parametre"
action="${addTreat}"
method="POST"
enctype="multipart/form-data">
<table>
<tr>
<td>xslx File : </td>
<td>
<f:input id="filepd" path="fileCom" name="filepd" type="file" />
</td>
</tr>
<tr>
<td>Choice </td>
<td>
<div>
<f:input id="az" name="az" path="choice" type="radio" value="false" />
<label for="az">1</label>
<f:input id="aj" name="aj" path="choice" type="radio" value="true"/>
<label for="aj">2</label>
</div>
</td>
</tr>
<tr>
<div align="center">
<f:input type="submit" value="Validate" path="" />
</div>
</tr>
</table>
</f:form>
for myController : 对于myController:
@RequestMapping(value="/addTreat", method= RequestMethod.POST)
public String addTr(HttpServletRequest req,
BindingResult result,
ModelMap model,
@RequestParam("parametre") Parametre parametre) {
model.addAttribute("parametre", new Parametre());
return form_li;
}
for the class Parametre.java: 对于Parametre.java类:
public class Parametre {
private String choice;
private MultipartFile fileCom;
//getters and setters
//default constructor
}
my problem is when running the application and going to the /addTreat url. 我的问题是运行应用程序并转到/ addTreat网址时。 im getting the famous Neither BindingResult nor plain target object for bean name 'parametre' available as request attribute. 我得到了著名的BeanResult'parametre'的BindingResult或普通目标对象都不能用作请求属性。 i have tried multiple solutions but i doesn't work. 我尝试了多种解决方案,但我无法正常工作。 please can anyone help to fix this problem. 请任何人都可以帮助解决此问题。
So many things are messed up here, I recommend you to read some modelAttribute
examples, there are dozens, even on the official spring documentation. 这么多事情搞砸了,我建议您阅读一些modelAttribute
示例,即使在官方的spring文档中也有几十个。 It looks like you confuse model object with simple request param, for the second one you don't even need BindingResult
. 看起来您将模型对象与简单的请求参数混淆了,对于第二个对象,您甚至不需要BindingResult
。 Also the syntax of your form action is incorrect. 此外,表单操作的语法不正确。
action="${addTreat}"
change to action="/addTreat"
action="${addTreat}"
更改为action="/addTreat"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.