问题
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
}
}
Is this a change to grails 3 or am I missing something somewhere?
Thanks
回答1:
Try doing this
def index() {
def res = myService.whatever()
[res: res]
}
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>
来源:https://stackoverflow.com/questions/38170916/grails-3-1-8-controller