grails - Groovy下的Acegi用户类约束

标签 grails groovy validation spring-security

我有一个使用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/

相关文章:

groovy - 如何在Groovy中获得今天的日期

asp.net-mvc - 使用自定义 [必需] 属性时使用客户端验证

entity-framework - 首先更新 Entity Framework 代码中的记录的单个属性

hibernate - 是否可以在不获取引用域的情况下保存新的Grails域实例?

grails - 用户在Grails中取消了文件下载

mongodb - 在Mongodb上使用Grails时是否存在连接泄漏

windows - 为什么从函数返回的 gstrings 串联是一个空字符串 - Groovy 1.7.4

grails - 从 GroovyShell 脚本访问 Grails 域类

django - 尽管为 ModelForm 字段设置了 (null=True, Blank=True),但在将该字段留空时出现验证错误

grails - 对 Grails 中 each() 中的最后一项运行命令