我有以下情况:
@ModelAttribute("persons")
public void addAttributes(Model model) {
Person person = new Person()
;
person.setAge(26);
person.setFirstName("mars");
model.addAttribute("persons", person);
}
@RequestMapping(value="/process-person")
public ModelAndView processPerson(@ModelAttribute Person person,@ModelAttribute ("persons")Person persons,ModelAndView modelAndView ) {
//
//ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("person-result-page");
modelAndView.getModel().remove("personObj");
modelAndView.addObject("pers", person);
----> modelAndView.addObject("pers2", persons);// persons holds the myname1 provided in input box
modelAndView.addObject("personObj", person);
return modelAndView;
}
如 - >所示我希望这个变量-persons保存从addAttributes()方法获得的值,但它采用的是我从jsp页面输入的相同值:
<form:form method="POST" commandName="person-entity" action="process-person.html">
<table>
<tr>
<td><form:label path="firstName">Name:</form:label></td>
<td><form:input path="firstName" /></td>
</tr>
<tr>
<td><form:label path="age">Age:</form:label></td>
<td><form:input path="age" /></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit"/>
</td>
<td></td>
<td></td>
</tr>
</table>
</form:form>
<br/>
我看到几个类似的问题,但没有一个解决了这个问题。在这里,我希望将addAttribute方法的值放在&#34; person&#34;对象,但它与&#34; person&#34;的价值相同。由form.jsp提供。
请帮帮我