Grails:如何在不使用g:view的情况下读取错误(在控制器/服务中)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Grails:如何在不使用g:view的情况下读取错误(在控制器/服务中)相关的知识,希望对你有一定的参考价值。

how to read error message as string instead of complicated codes. usually people using taglib to read error messages. but how to read it in controller/service if you, for example, want to log or render just the message. here is how to do that.
  1. // in controller/services :
  2. class GrailsService {
  3. boolean transactional = true
  4. def messageSource ;
  5.  
  6. def locale = Locale.getDefault()
  7. domainObj.errors.each { fieldErrors ->
  8. fieldErrors.allErrors.each { error ->
  9. log.warn messageSource.getMessage(error, locale)
  10. }
  11. }
  12.  
  13. }

以上是关于Grails:如何在不使用g:view的情况下读取错误(在控制器/服务中)的主要内容,如果未能解决你的问题,请参考以下文章