def user=User.findByUserIdAndPassword(params.userId,params.password)
即使在成功注册后也为空......我正在使用 Spring Security。
我的用户域类是
class User {
transient springSecurityService
Integer id
String userId
String password
byte[] photo
String fullName
String bio
String email
String address
String username
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static hasMany = [places: Place, badges: Badge, checkIns:CheckIn, friend:User]
static belongsTo = Place
String toString(){
"$userId"
}
static constraints = {
fullName(nullable: true,maxSize:20,matches:"[a-zA-Z\40-\176]+")
bio(nullable: true, maxSize: 100,matches:"[a-zA-Z\40-\176]+")
email(email: true, blank: false)
photo(nullable: true,maxSize:1000000)
address( nullable:true,maxSize:40,matches:"[a-zA-Z0-9\40-\176]+")
userId(size:5..10,unique:true,nullable:false,matches:"[a-zA-Z][a-zA-Z0-9 ]+")
password(size:5..10,password:true,nullable:false)
username blank: false, unique: true
}
static mapping = {
password column: '`password`'
}
Set<Authority> getAuthorities() {
UserAuthority.findAllByUser(this).collect { it.authority } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
}
如果我实施
System.out.println(" userid------------------->" + params.userId);
System.out.println(" password------------------->" + params.password);
System.out.println(" username------------------->" + params.username);
我可以看到登录用户的用户 ID 和密码...但是为什么
def user=User.findByUserIdAndPassword(params.userId,params.password)
无效的??