我正在将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/