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 = { }
}
的文档是在这里: 托马什