1

我有一个 Grails 3.3.8 应用程序

  compile 'org.grails.plugins:views-json'
  compile 'org.grails.plugins:views-json-templates'

和下的 json 视图views/partner/_companion.gson

import io.my.domain.Companion

model {
  Companion companion
}
json {
  id companion.id
  name companion.name
  description companion.description
}

现在我想在控制器操作中将我的对象渲染为 json:

class PartnerController {
  def action() {
    Companion o = Companion.get(...)
    log.info render( view:"/partner/_companion", model:[ companion:o ] )
    log.info render( view:"_companion", model:[ companion:o ] )
    log.info render( template:"companion", model:[ companion:o ] )
    log.info render( template:"companion", model:o )
  }
}

所有这些马蹄莲输出null

什么是正确的渲染方式?

4

0 回答 0