简体   繁体   中英

How to write query in grails controller

I am using grails 1.3.7. I am sending username and password from my view page to controller. And it's rendering correctly on browser. But I need to write query for collect data with that username and password from database. But I have no idea how to write query in grails controller. Can anyone please help me on this ? Here is my action below where I want to write query for logging in to the home page >>>

def loginAction = {
    def username = params?.username
    def password = params?.password
    def val = username + "  ---  " +password
    render val
}

Something like:

def loginAction = {
    def username = params?.username
    def password = params?.password
    User user = User.findByUsername(username)
    def val = user?.password == password ? 'Valid' : 'Invalid'
    render val
}

But you really should read docs for GORM - http://grails.org/doc/latest/guide/GORM.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM