spring3 page form tag error Neither BindingResult nor plain target object for bean name

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name "company" available as request attribute When I
was learning spring mvc today, I wanted to make a form to fill in the company information, and then add it to the database, but the spring label kept reporting an error, For a long time, there has been no solution.
Later, Baidu and Google thought for a long time that before entering the form page, there must be a company object to be recognized in the form tag, so
the following content was added to the controller:
@RequestMapping(value="/addCompany",method = RequestMethod.GET)
public ModelAndView initForm(ModelMap model){
Company company = new Company(); //Object used to convert to form
return new ModelAndView("addCompany").addObject(company); //Jump to addCompany page
}
The form form of the addCompany page is as follows:
<!-- Before entering the form page, you must create a company object and put it in the context, otherwise an error will be reported -->
<form:form commandName="company" modelAttribute=" company" action="addCompany"

<legend>Account Fields</legend>
<p>
<form:label path="name">Name</form:label>           <!--这里对应company类中的name属性-->
<form:input path="name" /><form:errors path="name" />    
</p>
<p>
<form:label path="password">Password</form:label>   <!--这里对应company类中的name属性-->


<form:input path="password" /><form:errors path="password" />
</p>
<p>
<input id="create" type="submit" value="Create" />
</p>
</fieldset>
</form:form>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326490610&siteId=291194637