grails/gorm 消息捆绑问题
在我的 grails 应用程序中,我使用 GORM。我想为每个类自定义错误消息。想象一下我有这个类:
class City {
String name
Region regiao
District district
static belongsTo = District
static constraints = {
regiao(blank: false, nullable:false)
district(blank: false, nullable:false)
name(blank: false, nullable:false, unique: true)
}
String toString(){
name
}
}
我想自定义“messages.proprieties”中的错误消息。
想象一下我想为这个类制作一条错误消息。唯一的默认错误消息如下:
default.not.unique.message=Property [{0}] of class [{1}] with value [{2}] must be unique
我的错误消息将是这样的:?
packagename.City.not.unique.message= Must be unique !
请帮忙,我无法让它工作.. 提前谢谢。
In my grails application i use GORM. I want to customize error messages for each class. Imagine i have this class:
class City {
String name
Region regiao
District district
static belongsTo = District
static constraints = {
regiao(blank: false, nullable:false)
district(blank: false, nullable:false)
name(blank: false, nullable:false, unique: true)
}
String toString(){
name
}
}
i want to customize the error messages in "messages.proprieties".
Imagine i want to make an error message for this class. the default error message for unique is the following:
default.not.unique.message=Property [{0}] of class [{1}] with value [{2}] must be unique
My error message will be something like this: ?
packagename.City.not.unique.message= Must be unique !
Please help, i cant get this to work..
Thx in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑 - 事实证明答案就在文档中。约束部分中的每个约束都有要使用的属性路径。因此,对于 unique 来说,它的
className.propertyName.unique
但路径根据特定约束而变化。
EDIT -- turns out that the answer is in the documentation. Each constraint, in the Constraints section, has the property path to use. So for unique its
className.propertyName.unique
but the path varies according to the specific constraint.
好吧,就是这样。要确保消息语法如何,只需检查 grails 文档,在约束部分。对于每种类型的约束,最后都有相应的错误消息。
例如,转到: http://grails.org/doc/latest/
约束类型 'maxSize '错误如下:
错误代码:className.propertyName.maxSize.exceeded
ok so it is it. to make sure how message syntax is just check grails documentation, in constrains section. for each type of constrain, at the end there is the corresponding error message.
For example, go: http://grails.org/doc/latest/
The constrains type 'maxSize' error is the following:
Error Code: className.propertyName.maxSize.exceeded
您想要自定义以下消息。
default.not.unique.message=类 [{1}]
的属性 [{0}] 的值[{2}]
必须是唯一的我已尝试过以下代码它正在工作。
city.name.unique.error = 城市名称必须是唯一的。
或
city.name.unique.message = 城市名称必须是唯一的。
You want to customise below message.
default.not.unique.message=Property [{0}] of class [{1}]
with value[{2}]
must be uniqueI have tried below code it is working .
city.name.unique.error = city name must be unique.
or
city.name.unique.message = city name must be unique.