我有一个@ModelAttribute,我从另一个方法showHome调用。
@ModelAttribute
public void getAuthority(@ModelAttribute InputDataType authorityCreatedRequest, CountyInputDataType countryCreatedRequest, ParishInputDataType parishCreatedRequest, Model model)
{
model.addAttribute("authorityCreatedRequest", new ObjectFactory().createInputDataType());
CrrAuthorityResponseType authorityCreatedResponse = new ObjectFactory().createCrrAuthorityResponseType();
authorityCreatedResponse = (CrrAuthorityResponseType) ((JAXBElement<?>) rdwebServiceTemplate.marshalSendAndReceive(authorityCreatedRequest)).getValue();
model.addAttribute("authorityCreatedResponse", authorityCreatedResponse);
authorityList.clear();
authorityList.add( authorityCreatedResponse );
model.addAttribute("authorityList", authorityList);
}
问题是modelattribute正在执行2次。我不想多次执行它。有没有比@ModelAttribute更好的方法,我可以执行我需要的代码行。
@RequestMapping
public String showHome(@ModelAttribute InputDataType authorityCreatedRequest, CountyInputDataType countryCreatedRequest, ParishInputDataType parishCreatedRequest, Model model)
{
model.addAttribute("authorityList", authorityList);
return "crownreservereport";
}