我有兴趣将多个列表返回到视图,这样我最终可以在一个页面上显示来自完全不同查询的信息行.我已经想出如何做到以下几点:
这是我在我的控制器中的动作:
def processMultipleLists()
{
def stirList = []
Person stirling = new Person('Stirling','Crow', 47)
Person lady = new Person('Lady','McShavers', 4)
stirList << stirling
stirList << lady
def kathieList = []
Person kathie = new Person('Kathie','Esquibel', 47)
Person milagro = new Person('Milagro','Muffin', 4)
Person meeko = new Person('Meeko','Muffin', 4)
kathieList << kathie
kathieList << milagro
kathieList << meeko
def returnThisMap = [:]
returnThisMap.put('One', kathieList)
returnThisMap.put('Two', stirList)
return [returnMap : returnThisMap]
}
Run Code Online (Sandbox Code Playgroud)
然后Grails将"returnMap"(包含"returnThisMap",以下称为"mapNum")返回到我的视图,其中包含以下内容:
<g:if test="${returnMap.size() > 0}">
<table border="1">
<tbody>
<g:each …Run Code Online (Sandbox Code Playgroud)