Grails错误:没有这样的属性:它对于类:

时间:2010-09-22 03:58:17

标签: grails

以下是我的代码。 在这里,我收到一个错误,即“没有这样的属性:它为类:emp.EmployeeController”。 我想我在这里做错了什么。 有什么建议??

def list ={

    def id=params.id
    def results

    String employee="SELECT empName, empDate, empNo from employee where empId='id'"     
    String referrer="SELECT  empName, empDate, empNo from referer where empId='id'"


    def employeeInstanceList = new ArrayList<Employee>()
    Sql sql = new Sql(dataSource)
    def joining=null
    joining = sql.rows( "select joining from employee_dates")


    if (joining!=null)      
    results = sql.eachRow(employee)
    employeeInstanceList=getCalculatedEmployeeData(results)
    /*{

        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee
    }*/

    else

    results = sql.rows (currentDaySql)
    employeeInstanceList=getCalculatedEmployeeData(results)
    /*{
        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee       }*/ 

    }


    [employeeInstanceList: [employeeInstanceList: employeeInstanceTotal: Employee.count()]
}


def getCalculatedImpactData(def results){
        def employee = new Employee()
        employee.setempName it.empName
        employee.setEmpNo it.empNo
        employee.setEmpDate it.EmpDate
        employeeInstanceList.add employee       }*/
    return [employeeInstanceList: employeeInstanceList]
}

谢谢, Meghana

3 个答案:

答案 0 :(得分:2)

该代码存在很多错误,我不知道从哪里开始......

但为了避免获得更多的选票,我试过了:)

我尝试将您的代码复制到IDE中,然后尝试找出您想要实现的内容,但却无法实现。

这就像我能得到它一样接近:

 def list = {
        def id = parmas.id
        def results

        String employee = "SELECT empName, empDate, empNo from employe"

        def employeeInstanceList 
        Sql sql = new Sql(dataSource)
        def joining = sql.rows("select joining from employee_dates")

        if (joining != null) {
            results = sql.eachRow(employee)
            employeeInstanceList = getCalculatedEmployeeData(results)
        }
        else {
            results = sql.rows(currentDaySql)
            employeeInstanceList = getCalculatedEmployeeData(results)
        }

        [employeeInstanceList: employeeInstanceList, employeeInstanceTotal: Employee.count()]
    }


    def getCalculatedImpactData(def results) {
        def employeeInstanceList = new ArrayList<Employee>()
        results.each { it ->
            def employee = new Employee()
            employee.empName = it.empName
            employee.empNo = it.empNo
            employee.empDate = it.EmpDate
            employeeInstanceList.add(employee)
        }
        return employeeInstanceList
    }

但它仍然指的是一个不存在的变量currentDaySql,我不确定你要用'join'结果做什么。

你真的需要阅读Groovy的基础知识。

答案 1 :(得分:2)

我会第二个leebutts回答...但只是一个指针, it 关键字的用法通常仅限于闭包......所以不要在java中这样做:

List l = [];
for (Iterator i = l.iterator(); i.hasNext(); ) {
  ...do something adressing List l at position i...
}

你可以用groovy / grails做到这一点:

list.each { it ->
  ...do something with each object in the list (it)...
}

但是你应该在http://groovy.codehaus.org/Closures

上阅读groovy闭包

答案 2 :(得分:0)

发生错误的代码块可能是:

def getCalculatedImpactData(def results){
    def employee = new Employee()
    employee.setempName it.empName
    employee.setEmpNo it.empNo
    employee.setEmpDate it.EmpDate
    employeeInstanceList.add employee
    return [employeeInstanceList: employeeInstanceList]
}

it没有在任何地方定义(提示:编译错误告诉你这个)。就像塞巴斯蒂安所说,it通常用在封闭中;你在这里定义的是一个函数。大概你想在这里使用results(或其他东西)代替it

我假设代码中的某些内容(例如评论打开/关闭)不在那里,并且在您看到错误和发布代码之间添加。否则你会得到其他错误。