Grails 3.1.8控制器 [英] Grails 3.1.8 controller

查看:82
本文介绍了Grails 3.1.8控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将grails 2.4.4应用程序转换为3.1.8. 有时,在某些控制器方法中(基于服务调用中发生的情况),我只会在Flash中设置一条消息,而在其他其他方面,这在2.4.4中就可以了,该屏幕将使用Flash消息重新呈现但是在3.1.8中,什么也没有渲染,屏幕完全空白. 看来,如果我在设置Flash消息后添加了一条语句,就会渲染屏幕,该语句可以是任何形式,例如println'hello'或return或新的ModelAndView(). 下面的示例:

I'm converting a grails 2.4.4 app to 3.1.8. In some of my controller methods sometimes (based on what happened in the service call) I'll just set a message in the flash and nothing else, this was fine in 2.4.4, the screen would be re-rendered with the flash message but in 3.1.8 nothing is rendered at all, the screen in totally blank. Seemingly if I add a statement after setting the message in the flash the screen is rendered, the statement can be anything e.g. println 'hello' or return or new ModelAndView(). Example below:

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还是我在某处缺少某些东西?

Is this a change to grails 3 or am I missing something somewhere?

谢谢

推荐答案

尝试执行此操作

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

    [res: res]
}

然后在index.gsp视图中

Then in the index.gsp view

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

这篇关于Grails 3.1.8控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆