我使用 Grails 作为服务器,使用 ExtJS 作为客户端。现在我需要使用 JSON 中的特定日期值更新域的日期字段。但是当我想用特定日期更新时,错误是这样的
无法将具有类“java.lang.String”的对象“dd MM,yyyy”转换为类“java.util.Date”
现在如何将特定日期从 JSON 更新到数据库中?这是我的服务器更新操作:
def update(json) {
def count = 0
def flag = true
def installments = []
def pdate = json.payDate
def payDate = pdate.format("dd MM, yyyy")
def newCashPay = Double.parseDouble("${json.cashPay}")
def newReturnAmount = Double.parseDouble("${json.returnAmount}")
if(json instanceof JSONObject){
def c = Installment.get(Integer.parseInt("${json.id}"))
if(c){
c.activeFlag = true
c.cashPay = newCashPay
c.returnAmount = newReturnAmount
c.payDate = payDate
if(c.validate()){
c.save()
}else{
c.errors.each {
println it
}
}
}
def installment = [id:c.id, accNo:c.accNo, memberNo:c.memberNo, branchId:c.branchId, installmentNo:c.installmentNo, weekStart:c.weekStart, weekEnd:c.weekEnd, payDate:c.payDate, payAmount:c.payAmount, lateFee:c.lateFee, cashPay:c.cashPay, returnAmount:c.returnAmount, activeFlag:c.activeFlag]
installments << installment
flag = flag && true
count++
}
}