【发布时间】:2018-02-22 01:45:45
【问题描述】:
我有一个控制器来检查Command Object 是否有效。如果不是,我会呈现错误template:
if (!cmdObj.validate()) {
render (status: 400, template:'error', model: [errorObj: cmdObj])
return
}
然后在错误 template 中,我有以下代码来呈现 bean 中的所有错误
<div>
<g:hasErrors bean="${errorObj}">
<div class="error-messages">
<g:renderErrors bean="${errorObj}"/>
</div>
</g:hasErrors>
</div>
这很好用。但是,我想在处理异常时使用相同的错误template。例如,在同一个控制器中,我有一个处理异常的方法:
def handleMyCustomException(MyCustomException e) {
render (status: 500, template:'error', model: [errorObj:e])
}
这不起作用,因为Exception 不是 Grails 可以用来呈现错误的 bean。
有没有一种方法可以将我的错误 template 重复用于无效的 bean 和异常?
我正在使用 Grails 2.4.4
【问题讨论】:
标签: grails