我面临着与前面提到的here相同的问题,但是当我厌倦了解决方案中的内容时,我仍然会得到相同的错误:
属性startDate必须是有效日期属性endDate必须是有效日期。
这是我的域名:
class EmpRef {
String workName
String title
Date startDate
Date endDate
String reasonForLeaving
String directMgrName
String directMgrTitle
String directMgrTelephone
}
以下是我的拯救行动:
def save(EmpRef empRefInstance) {
empRefInstance.startDate=Date.parse('dd-MM-yyyy',params.startDate)
empRefInstance.endDate=Date.parse('dd-MM-yyyy',params.endDate)
if (empRefInstance == null) {
notFound()
return
}
if (empRefInstance.hasErrors()) {
respond empRefInstance.errors, view:'create'
return
}
empRefInstance.save flush:true
}
普惠制中的jQuery代码:
$('.datePicker').datepicker({
changeYear: true,
changeMonth: true,
autoSize: true,
dateFormat: "dd-mm-yy",
maxDate: "0y",
showAnim: "show",
yearRange:'c-70:c+0'
});
发布于 2016-05-13 02:57:02
如果EmpRef
是方法的参数,则会根据请求自动绑定它。这会导致startDate
和endDate
都有错误。在对这些列设置值之后,需要执行empRefInstance.validate()
而不是empRefInstance.hasErrors()
,以便在域中获得新的验证结果。
另外,由于在设置“开始日期”和“结束日期”之后检查empRefInstance
是否为空,因此如果该对象为空,则将在前面的行中获得NullPointerException,因此应在代码中的前面进行检查。
https://stackoverflow.com/questions/37205746
复制相似问题