我有一个使用Acegi Spring Security的Groovy应用程序。
我的用户类如下所示:
class User {
static constraint = {
email(blank:true, nullable:true)
description(blank:false, nullable:false)
username(blank: false, unique: true)
userRealName(blank: false)
company(nullable:true, blank:true)
authorities()
enabled()
passwd(blank: false)
}
static mapping = {
table 'user_table'
}
static transients = ['pass']
static hasMany = [authorities: Role]
static belongsTo = Role
String username
String userRealName
String passwd
boolean enabled
String email
boolean emailShow
String description = ''
String pass = '[secret]'
Company company
}
请注意,公司可为可为空,而用户名不可为可为空。
我已经生成了 View 和 Controller ,没有任何问题。
当我尝试插入新用户(没有公司)时,出现错误
消息告诉我,公司是是强制性的。 (我已经验证
数据库中的字段,它可以为空)
另一方面,当我生成一个没有用户名的用户时-应该禁止该用户名-
验证程序不会报告任何错误,尽管即将发生异常
尝试在非null字段中插入null时。
我在这里做错了什么?
提前致谢,
路易斯
最佳答案
将“静态约束”更改为“静态约束”。
关于grails - Groovy下的Acegi用户类约束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2050498/