Spring 在需要时执行代码行
我从另一个showHome方法调用了@ModelAttributeSpring 在需要时执行代码行,spring,velocity,Spring,Velocity,我从另一个showHome方法调用了@ModelAttribute @ModelAttribute public void getAuthority(@ModelAttribute InputDataType authorityCreatedRequest, CountyInputDataType countryCreatedRequest, ParishInputDataType parishCreatedRequest, Model model) { mod
@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);
}
别这么说
@modeldattribute
在任何请求处理方法之前自动调用带注释的方法。无需手动调用。@M.Deinum谢谢您提供的信息。我删除了line model.addAttribute(“authorityList”,authorityList);在showHome方法内部。我仍在获取权限列表,但如果我查看tcp/ip监视器内部,我可以看到getAuthority正在执行多次。我怎样才能停止呢?正如我提到的,@modeldattribute
带注释的方法在每个请求处理方法之前执行。如果您的控制器有两个被调用的方法(例如,呈现响应是另一个方法),您还将得到两个调用@modeldattribute
注释方法。谢谢@M.Deinum。现在我明白了。
@RequestMapping
public String showHome(@ModelAttribute InputDataType authorityCreatedRequest, CountyInputDataType countryCreatedRequest, ParishInputDataType parishCreatedRequest, Model model)
{
model.addAttribute("authorityList", authorityList);
return "crownreservereport";
}