代码之家  ›  专栏  ›  技术社区  ›  Christian von Wendt-Jensen

Grails CXF插件Web服务

  •  1
  • Christian von Wendt-Jensen  · 技术社区  · 15 年前

    我想知道当作为webservice请求接收请求时,处理现有实体(例如个人)更新请求的最佳方式是什么。

    static expose = ['cxfjax']
    

    然后我有了更新方法:

    @WebResult(name = "person")
    @WebMethod(operationName = "update")
    Person update(@WebParam(name="person")Person person) {
      println "Updating $person"
      return person.save()
    }
    

    在服务中,我得到了一个fine Person对象,但即使它有一个现有人员的id,也会创建一个新人员,并更改id以反映这一点。

    亲切问候,,

    2 回复  |  直到 15 年前
        1
  •  0
  •   Aaron Saunders    15 年前

    大概

    @WebResult(name = "person")
    @WebMethod(operationName = "update")
    Person update(@WebParam(name="person")Person person) {
    
      println "Updating $person"
      def p = Person.get(person.id)
      if ( p ) {
         // what ever your merge logic is...
      } else {
         return person.save()
      }
    }
    
        2
  •  0
  •   Scott Warren    15 年前

    不是100%确定,但确实如此 attach() 工作即

    @WebResult(name = "person")
    @WebMethod(operationName = "update")
    Person update(@WebParam(name="person")Person person) {
      println "Updating $person"
      person.attach();
      return person.save()
    }
    

    我认为这就是方法的要点。