使用SQL Query登录Grails



我正在研究圣杯,我是新手。我需要在圣杯中使用sql查询登录。请帮助我。这是我的视图页面、控制器和域类。

登录.gsp

    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="layout"content="main"/>
        <g:set var="entityName" value="ProjectTracker Login" />
        <title><g:message code="projectTracker login" args="[entityName]" /></title>
      </head>
      <body>
        <div class="nav" role="navigation">
          <ul>
            <li><a class="home" href="${createLink(uri:"/")}"></a></li>
            <li><g:link class="list" action="logout">Logout</g:link></li> 
          </ul>
        </div>
        <div id="create-endUser" class="content scaffold-create" role="main">
           <h1>Login</h1>

                <g:form action="authenticate" >
                    <fieldset class="form">
                        <div class="fieldcontain ${hasErrors(bean: endUserInstance, field: 'userName', 'error')} ">
                            <label for="userName">
                                <g:message code="endUser.userName.label" default="User Name" />
                            </label>
                            <g:textField name="userName" value="${endUserInstance?.userName}"/>
                        </div>
                        <div class="fieldcontain ${hasErrors(bean: endUserInstance, field: 'password', 'error')} ">
                            <label for="password">
                                <g:message code="endUser.password.label" default="Password" />
                            </label>
                            <g:field type="password" name="password" value="${endUserInstance?.password}"/>
                        </div>
                    </fieldset>
                    <fieldset class="buttons">
                        <g:submitButton name="login" class="save" value="Login" />
                    </fieldset>
                </g:form>
        </div>
      </body>
    </html>

我的域类

Testuser.groovy

class Testuser {
     String userName
        String password
        String fullName
        String toString(){
            "${fullName}"
        }
    static constraints = {
        fullName();
        userName(unique:true);
        password(password:true);
    }
}

我的控制器是

TestuserController.groovy

import groovy.sql.*
   def index()
{
    redirect(action:"login")
}
 def login={ }
     def authenticate={

     def username_log = parmas.userName
     def password_log = parmas.password
        def results 
         Sql sql = new Sql(dataSource)
        def joining = sql.rows("SELECT user_name,password from user where user_name=username_log and password=password_log")
        {
             results << it.toRowResult()
        }
        results
          if (joining != null) {
            results = sql.eachRow()
            redirect(action:"login")
        }
        else {
            redirect(action:"login")
        }

这是我使用 SQL 查询进行简单登录的代码,我收到类似

URI
/login/testuser/authenticate
Class
groovy.lang.MissingPropertyException
Message
No such property: parmas for class: login.test.TestuserController Possible solutions: params
这不是

parmas而是params

您想在不使用 Spring 安全性的情况下实现登录吗?

顺便说一下,SQL查询应该是这样的

"SELECT user_name,password from user where user_name=$username_log and password=$password_log"

你忘了 $

相关内容

  • 没有找到相关文章

最新更新