2015-03-13 55 views
1

我使用导出插件如何在grails中导出json文件?

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' 
} 

普惠制代码: -

<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 
+0

您有:params =“[formattext:'json']”...根据http://grails.org/plugin/export格式(应该显示的格式,字符串列表,例如['csv' ,'excel','ods','pdf','rtf','xml'])。我认为如果我理解正确,你正试图导出到JSON?或者你可能会混淆你自己,你的意思是将JSON导出为CSV或PDF格式,而formattext应该是其中的一种,而不是 – Vahid 2015-03-13 09:29:39

+0

我希望以json格式导出.. – 2015-03-13 09:53:39

回答

0

假设您在Grails中使用export plugi n,则需要实现自己的JSON导出器。它不是默认包含的,但是如果你实现了Exporter接口并在你的Resources.groovy中注册为原型bean,那么你应该可以使用你自己的JSON导出器。