grails - Grails 3.1.8 Controller

标签 grails grails-3.1

我正在将grails 2.4.4应用程序转换为3.1.8。
有时,在某些 Controller 方法中(基于服务调用中发生的情况),我只会在Flash中设置一条消息,除此之外,别无其他,这在2.4.4中是可以的,屏幕将使用Flash消息重新呈现但是在3.1.8中,什么也没有渲染,屏幕完全空白。
看来,如果我在设置Flash消息后添加了一条语句,就会渲染屏幕,该语句可以是任何形式,例如println'hello'或return或新的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的更改,还是我在某处缺少某些东西?

谢谢

最佳答案

试试这个

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

    [res: res]
}

然后在index.gsp View 中
<g:if test="${res}">
    <!-- cool thing goes here -->
</g:if>
<g:else>
    <g:message code="no.res"/>
</g:else>

关于grails - Grails 3.1.8 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170916/

相关文章:

grails - Grails全局存储库凭据

grails - 建立关系后保留 Grails 域 *仅*

chalice 2.5 : how to propogate the IP address down to service layer?

grails - 如何在REST Web服务中为Grails创建Json?

Grails无法安装插件

grails - 以编程方式访问/检查 Spring Security 分层角色

Grails Controller /集成测试成功但永远挂起

grails - 无法在 Grails 3.1.1 中安装 HTML5 拖放多文件上传插件

grails 错误 : grails. 验证。Validateable 不是 @grails.validation.Validateable 中的注释

xml - Grails 3-具有XML的Marshaller