【问题标题】:executeUpdate in grails在 grails 中执行更新
【发布时间】:2017-10-25 06:14:34
【问题描述】:

我希望用 executeUpdate 来做这件事,事情是在 GRAILS 中用 executeUpdate 连接一个字符串值

def transactions = Transaction.findAll()

for (tr in transactions) {
   tr.comment = tr.comment + " new words...."
   tr.save()
}

【问题讨论】:

    标签: grails hql


    【解决方案1】:

    我没有尝试过,但是类似的东西

    Transaction.executeUpdate("update Transaction t set t.comment=t.comment + :newComment", [newComment: 'new words...'])
    

    Transaction.executeUpdate("update Transaction t set t.comment=concat(t.comment, :newComment), [newComment: 'new words...'])
    

    【讨论】:

      【解决方案2】:
         def transactions = Transaction.all  //you can use  findAll() also
          for (Transaction tr : transactions) {
             tr.comment = tr.comment + " new words...."
             tr.save(flush:true)
          }
      

      希望对你有帮助

      【讨论】:

      • 当然可以,Rahul,但这个想法不是在记录中迭代,而是在一个查询中完成,
      • @israel-laguna 我认为您需要编写本机查询
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-28
      • 1970-01-01
      • 2012-06-25
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      相关资源
      最近更新 更多