6

在 Grails 应用程序的 messages.properties 文件中,我看到了验证消息的示例,例如:

User.password.size=Size of bar must be between {0} and {1}

适用于

class User {

    String password
    static constraints = {
        password(size:5..15)
    }
}

此示例假定 {0} 绑定到最小大小,而 {1} 绑定到最大大小,但我找不到任何文档说明每个内置约束的错误消息可能使用哪些参数。换句话说,我想知道的是:对于每个内置约束,{0}....{n} 的含义是什么

4

2 回答 2

6

我做了一些实验,发现对于以下约束:

class User {    
    String password
    static constraints = {
        password(size:5..15)
    }
}

占位符的值是:

 0. Name of the class (User)
 1. Name of the property (password)
 2. Value of the property
 3. First constraint parameter (5)
 4. Second constraint parameter (15)
 5. etc.
于 2009-07-16T13:27:49.997 回答
0

你是对的,我也从来没有找到任何文档。最好的选择?将您的消息更改为:

User.password.size=0:{0}, 1:{1}, 2:{2}, etc...

看看你对每一个感兴趣的人都会得到什么。如果你将该信息发布到 Grails 上的 Nabble 留言板,我相信它会在文档中找到它。

祝你好运。

于 2009-07-15T16:20:07.887 回答