2009-07-13 47 views
6

在messages.properties在Grails应用程序文件我看到诸如验证消息的示例:参数Grails的验证消息

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}

回答

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. 
+0

default.blank.message =属性[{0}]类[{1}]的类不能为空 – Gepsens 2011-10-04 15:16:00

0

你说得对,我从来没有发现任何文档那也是。最好的选择?改变你的消息是这样的:

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

,看看你会得到什么为每一个你感兴趣如果你张贴信息,以中,Grails的Nabble留言板,我敢肯定,它会发现它的方式。进入文档。

祝你好运。