0

在控制器中,如何将 json 视图输出重定向到文件而不是 http 响应?

圣杯 3.2.5。

4

2 回答 2

0

另一个简单的选择是:

def action() {
    def json = [ key1:'value1', key2:[ key21:'value21' ]
    new File( '/the/path' ).withOutputStream{ it << ( json as JSON ) }
    [ some:result ]
}
于 2018-02-21T13:26:32.330 回答
0

你可以做这样的事情......

@Autowired
JsonViewTemplateEngine templateEngine

void myMethod() {
    Template t = templateEngine.resolveTemplate('/book/show')
    def writable = t.make(book: new Book(title:"The Stand"))
    def fw = new FileWriter(...)
    writable.writeTo( fw )
    ...
}
于 2018-02-19T19:38:03.977 回答