I’m facing a problem with the syntax for IF conditions in grails.
This is the code:
int ab = 9999
println(ab+"ab")
println(params.username+"parameter")
if (params.username == ab)
{
println("hello")
}
else
{
println("fail")
}
This is the codes in GSP:
<form>
Username:<g:textField name ="username"></g:textField>
<g:actionSubmit value="Submit" action="abc" type="button"/>
</form>
The result is:
9999ab
9999parameter
fail
So the problem is, I want the codes to print hello. But whenever I key in the “9999” in username textfield. It just doesn’t go through the condition and immediately goes to else. Anybody knows what is going on?
Thank you so much
You are trying to compare a String with a int, you can do the following:
Or if you want to compare integers: