Grails 3.1.8控制器

时间:2016-07-03 14:28:28

标签: grails grails-3.1

我正在将grails 2.4.4 app转换为3.1.8。 在我的一些控制器方法中有时(基于服务调用中发生的事情)我只是在闪存中设置一条消息而没有别的,这在2.4.4中很好,屏幕将使用flash消息重新呈现但在3.1.8中根本没有渲染,屏幕完全空白。 看起来如果我在闪存中设置消息之后添加一个语句,则呈现屏幕,该语句可以是任何例如println'hello'或return或new ModelAndView()。 示例如下:

def index() { 
def res = myService.whatever() 
if (res) { 
    [res: res] 
} 
else { 
    flash.message = message( code: 'no.res' )  // if we get here nothing is rendered
}
} 

这是对grails 3的改变还是我在某处丢失了某些东西?

由于

1 个答案:

答案 0 :(得分:0)

尝试这样做

def index() { 
    def res = myService.whatever() 

    [res: res]
}

然后在index.gsp视图中

<g:if test="${res}">
    <!-- cool thing goes here -->
</g:if>
<g:else>
    <g:message code="no.res"/>
</g:else>
相关问题