1

我有一个域类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)

无法解析的日期“3-12”。我只想根据月份和年份列出记录。

可能是什么问题?

4

1 回答 1

0

扔掉你的空间

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

为我工作

如果您需要更多控制和简化日期解析,请尝试  Joda-Time

于 2012-06-20T15:30:27.870 回答