【问题标题】:how to export json file in grails?如何在grails中导出json文件?
【发布时间】:2015-03-13 07:24:46
【问题描述】:

我正在使用导出插件

compile ":export:1.5"

控制器代码:

def exportJson(){
    if(!params.max) params.max = 10

    if(params.formattext){
        response.contentType = grailsApplication.config.grails.mime.types[params.formattext]
        response.setHeader("Content-disposition", "attachment; filename=BookList.${params.formattext}")


        exportService.export(params.formattext, response.outputStream,Book.list(),[:], [:])
    }
    response action:'index'
}

Gsp 代码:-

<g:link action="exportJson" params="[formattext:'json']" class="btn btn-primary btn-sm" style="margin-right: 30px; float: right; margin-top: 10px;" >Export Rules</g:link></div>

当我试图在 json 文件中导出书单时,它给了我错误

No bean named 'jsonExporter' is defined. Stacktrace follows:
Message: No bean named 'jsonExporter' is defined

【问题讨论】:

  • 你有:params="[formattext:'json']" ...根据grails.org/plugin/export格式(应该显示的格式,字符串列表,例如['csv','excel '、'ods'、'pdf'、'rtf'、'xml'])。我想如果我理解正确,您正在尝试导出到 JSON 吗?或者您可能会感到困惑,并且您的意思是将 JSON 导出为 CSV 或 pdf 或其他格式,而 formattext 应该是其中之一
  • 我想以 json 格式导出..

标签: json grails export grails-plugin grails-2.0


【解决方案1】:

假设您将export plugin 用于 Grails,您将需要实现自己的 JSON 导出器。默认情况下不包含它,但如果您实现Exporter 接口并将其注册为Resources.groovy 中的原型bean,那么您应该能够使用自己的JSON 导出器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2013-11-26
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    相关资源
    最近更新 更多