简体   繁体   English

在 controller 中的后续命令对象上初始化命令 object 时出错

[英]Error occurred initializing command object on succeeding command objects in controller

I have the defined following controller我定义了以下 controller

class BookController {

  def book(BookCommand bookCommand,
           AnotherBookCommand bookCommand2) 
  {
    ....
  }

When I debugged it, binding is done on the bookCommand and when it's bookCommand2's turn for binding, it throws this exception当我调试它时,绑定是在 bookCommand 上完成的,当轮到 bookCommand2 绑定时,它抛出这个异常

Error in object 'bookCommand2': codes []; arguments []; default message [Error occurred initializing command object [bookCommand2]. org.apache.groovy.json.internal.Exceptions$JsonInternalException: Wrapped Exception
 CAUSE java.io.IOException :: Stream closed]

If I try to switch the order of the parameters ie如果我尝试切换参数的顺序,即

class BookController {

  def book(AnotherBookCommand bookCommand2,
           BookCommand bookCommand) 
  {
    ....
  }

Binding is done on the bookCommand2 and binding of bookCommand throws the exception.绑定是在 bookCommand2 上完成的,而 bookCommand 的绑定会抛出异常。

Error in object 'bookCommand': codes []; arguments []; default message [Error occurred initializing command object [bookCommand]. org.apache.groovy.json.internal.Exceptions$JsonInternalException: Wrapped Exception
 CAUSE java.io.IOException :: Stream closed]

Any idea what's happening here?知道这里发生了什么吗?

We do not support binding the request of the body to multiple command objects.我们不支持将正文的请求绑定到多个命令对象。 One option you have is to aggregate them into 1 class with something like this:您的一个选择是将它们聚合成 1 class,如下所示:

class SomeClass {
    BookCommand bookCommand
    BookCommand anotherBookCommand
}

Then have your controller action accept one of those and organize the body of the JSON accordingly.然后让你的 controller 动作接受其中之一并相应地组织 JSON 的主体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM