我如何覆盖Grails中的默认错误消息?

问题描述:

我有一个带有姓氏字段的Person对象。 lastName字段不能为空。当用户在lastName字段中提交表单空白值时,用户看到的错误消息是:

I have a Person object with a lastName field. The lastName field cannot be blank. When the user submits a form blank value in the lastName field, the error message that the user sees is:

Property [lastName] of class [com.example.Person] cannot be blank

这个错误信息是蹩脚的。我想将它定制为更加用户友好的内容,比如姓氏字段不能为空

This error message is lame. I want to customize it to something more user friendly, like "The Last Name field cannot be blank"

我该怎么做?

请参阅文档的第7章: http: //grails.org/doc/latest/

See Chapter 7 of the docs: http://grails.org/doc/latest/

您可以更改 grails-app / i18n / messages.properties 并添加

You would change grails-app/i18n/messages.properties and add

person.lastName.blank=The Last Name field cannot be blank