2010-03-12 21 views
3

較早我使用Spring MVC和annotation @ModelAttribute。如何爲每個動作設置模型屬性

@Controller 
public class ArticleController { 

    @ModelAttribute("articles") 
    public List<Testset> getArticles(){ 
     return articleDao.all(); 
    } 

    @RequestMapping("/first.htm") 
    public void first(){      

    } 
} 

在Grails控制器中如何做到這一點?

class ArticleController{ 

    //this variable I want to in every action 
    List articles 

    def first = { } 
    def second = { } 
    def third = { } 
} 

當然,我可以使用此代碼爲每一個行動

def first = { 
    this.articles = Article.all() 
} 

但我想不是這個。

非常感謝您的幫助。此

class ArticleController { 

    def afterInterceptor = { model -> 
     model.articles = Article.list() 
    } 

    def first = { } 
    def second = { } 
    def third = { } 
} 

的文檔是在這裏: 托馬什

回答

相關問題