I’m new to Grails, and having a problem that is no doubt trivial, but I cannot find anything online!
I have a class:
package lib
class Login {
String name
String email
String password
String phonenumber
static constraints = {
}
}
In my Bootstrap file I create two instances of this class:
new Login(email:"tom", password:"password1")
new Login(email:"ian", password:"password2")
Now I have set up a Login form and I am trying to loop over these values and do something if they match:
def submit() {
def result = Login.findAll { email == params.email && password == params.password }
if (result.size() > 0) {
println "good login"
}
else {
println "bad login"
}
// some other stuff
}
The problem is that it is printing “bad login” every time, every when the entered email and password match those declared in the Bootstrap file. It’s probably just a misunderstanding on my end, but I can’t figure it out!
Thanks.
phonenumberandnameare null in your initialisation. Therefore the users cannot be persisted in your bootstrap.groovy. Double check, that save works: