2013-01-12 198 views
0

我使用Grails作爲服務器和ExtJS作爲客戶端。現在我需要從JSON更新具有特定日期值的域的日期字段。但是,當我想具體的日期錯誤是想更新此解析JSON日期

不能施放對象「DD MM,YYYY」帶班「java.lang.String中」上課「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++ 
    } 
} 

回答

3

而不是

def payDate = pdate.format("dd MM, yyyy") 

不要你的意思

def payDate = Date.parse("dd MM, yyyy", pdate) 
+0

是的,這是解決方案。非常感謝 –