【发布时间】:2014-12-03 07:01:32
【问题描述】:
如何从 GORM 视图中隐藏 password 列:
我的域类:
class SecUser {
static scaffold = true
transient springSecurityService
String username
String password
boolean enabled = true
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static transients = ['springSecurityService']
static constraints = {
username blank: false, unique: true
password (display:false, blank: false)
}
static mapping = {
password column: '`password`'
}
Set<SecRole> getAuthorities() {
SecUserSecRole.findAllBySecUser(this).collect { it.secRole } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
// password = password
}
}
【问题讨论】:
-
为什么在域类中有
static scaffold = true? -
这是一个例子。如果我删除它,它并不能解决我的问题
-
我不希望删除它会解决问题。通常,该属性在域类中是没有意义的,除非您的应用程序(或您的应用程序正在使用的插件)中有代码对该属性执行某些操作。我认为默认的脚手架插件可以识别控制器中的该属性。