我的程序中有一段代码试图解析日期,然后将其设置为等于这样的对象的属性:
if (newIndividualRecord.dateOfBirth == null || newIndividualRecord.dateOfBirth == "-")
newIndividualRecord.dateOfBirth = null
else {
def date = { ->
try {
Date.parse('dd-MM-yyyy', newIndividualRecord.dateOfBirth)
}
catch(e) {
newIndividualRecord.dateOfBirth = null
/* Should an incorrectly formatted date be reported as an error here? */
}
}()
if (date.getClass() == java.util.Date)
newIndividualRecord.dateOfBirth = date
}
我在读取为
def date = { ->
的行中收到此错误:| Error 2014-07-29 20:46:15,892 [http-bio-8080-exec-7] ERROR errors.GrailsExceptionResolver - MissingPropertyException occurred when processing request: [POST] /FatcaOne_0/customer/upload - parameters:
dataTypegrp: 1
fileTypegrp: 1
No such property: for class: java.util.Date
Possible solutions: day. Stacktrace follows:
Message: No such property: for class: java.util.Date
Possible solutions: day
Line | Method
->> 788 | $tt__processNewIndividualRecordFlags in com.twc.fatcaone.FileImportService$$EOlRGIsK
我似乎无法弄清楚这个错误是什么意思。任何帮助将不胜感激。谢谢。
最佳答案
它尝试在日期上使用属性”(空字符串)。该属性不存在,并且出现错误No such property: for class: java.util.Date
。
我无法重现该错误。
这可以(使用grails 2.4.2),也可以在所有没有if / else的情况下使用。如果源值为null或“-”,则如果解析成功,它将抛出并返回null或Date
。
def record = [:]
//record.dateOfBirth = "-"
record.dateOfBirth = {
try {
Date.parse ('dd-MM-yyyy', record.dateOfBirth)
}
catch (Exception ignore) {
null
}
}()
关于grails - Groovy日期解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25024884/