【问题标题】:Grails 2.3.1 Command Object Data Binding at Controller ParametersGrails 2.3.1 控制器参数处的命令对象数据绑定
【发布时间】:2013-11-07 04:55:34
【问题描述】:

我最近从 grails 2.2 升级到 2.3.1。我的控制器曾经以控制器参数将数据绑定到命令对象。升级到 2.3.1 后,绑定似乎无法正常工作,并且出现“[致命错误]:-1:-1:文件过早结束。”输出到控制台。

像这样在 2.2 下可以正常工作 def home(ACommand cmd) {}

升级后,在进入action前输出'Premature end of file',跳过action方法直接进入home.gsp视图。

我还尝试在操作中新建一个实例并使用 bindData(cmd, params)。当我逐步执行该操作时,bindData 方法产生了相同的消息,但可以继续并生成视图模型并传递给 home.gsp。

有没有人碰巧知道可能导致问题的原因?谢谢。

【问题讨论】:

    标签: grails data-binding command-objects


    【解决方案1】:

    Grails 2.3 包含一个新的数据绑定机制,该机制具有附加功能。如果您需要访问旧版 spring 数据绑定机制,请在 Config.groovy 中使用此配置

    grails.databinding.useSpringBinder=true
    

    最终,如果您觉得需要使用 latest data binder,则需要转换为使用 new features

    【讨论】:

      【解决方案2】:

      感谢 dmahapatro。之前试过了,还是不行。

      仅供参考,我通过在 Config.groovy 重新安排内容协商来修复它。

      改变

      mime.types = [ xml: ['text/xml', 'application/xml'],
              text: 'text/plain',
              js: 'text/javascript',
              rss: 'application/rss+xml',
              atom: 'application/atom+xml',
              css: 'text/css',
              csv: 'text/csv',
              all: '*/*',
              json: 'text/json',
              html: ['text/html','application/xhtml+xml']
      ]
      

      mime.types = [
              all:           '*/*',
              atom:          'application/atom+xml',
              css:           'text/css',
              csv:           'text/csv',
              form:          'application/x-www-form-urlencoded',
              html:          ['text/html','application/xhtml+xml'],
              js:            'text/javascript',
              json:          ['application/json', 'text/json'],
              multipartForm: 'multipart/form-data',
              rss:           'application/rss+xml',
              text:          'text/plain',
              hal:           ['application/hal+json','application/hal+xml'],
              xml:           ['text/xml', 'application/xml']
      ]
      

      解决问题。

      不确定为什么顺序很重要,但我认为这是由于 Grails 2.3 数据绑定打算解析请求正文并绑定到我的命令对象并导致 xml 解析器错误。

      【讨论】:

        猜你喜欢
        • 2011-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-31
        • 1970-01-01
        相关资源
        最近更新 更多