namedQueries错误grails

时间:2012-06-20 11:33:23

标签: grails dynamic-queries

我有一个域类DefectData,如下所示

class DefectData {
String taskId
String defectId
String defectSummary
String severity
String phaseDetected
String rejected
String loggedBy
String howFound
Date dateFound 
String defectType
String defectCause
ProgressData progressData
def DefectData(){}

static constraints = {
    id generator:"assigned",name:"defectId"

}
static belongsTo=[taskId:ProgressData]
static namedQueries={
    getDefectDataByYearMonth{int month,int year ->
    def plannedDate=Date.parse("mm-yy","${month} - ${year}")
    }
}
}

我正在尝试这种查询,这将使我能够在“测试”阶段检测到缺陷的计数。

 def testingDefects(int month,int year){
          countTestingDefects=DefectData.getDefectDataByYearMonth(month,year).findAllWhere(phaseDetected:"Testing").count()
    println countTestingDefects
}

虽然,我收到此错误,但日期不可解析

testingDefects(03,2012)

Unparsable date“3-12”。我只想根据月份和年份列出记录。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

扔掉你的空间

def (month,year) = [2,2012]
Date.parse("mm-yy","${month}-${year}")

适合我

如果您需要更多控制并轻松进行日期解析,请尝试Joda-Time