Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 在需要时执行代码行_Spring_Velocity - Fatal编程技术网

Spring 在需要时执行代码行

Spring 在需要时执行代码行,spring,velocity,Spring,Velocity,我从另一个showHome方法调用了@ModelAttribute @ModelAttribute public void getAuthority(@ModelAttribute InputDataType authorityCreatedRequest, CountyInputDataType countryCreatedRequest, ParishInputDataType parishCreatedRequest, Model model) { mod

我从另一个showHome方法调用了@ModelAttribute

@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"; 
    }