renderの結果をファイルに保存したい - grails 2013/10/19

grailsです。
gspのレンダリングの結果を、サーバーに保存したいなーと思ったわけです。静的HTMLファイルとして保存したいという方式を考え中なのですが、その一環としての調査です。


renderの結果を一時変数に渡して、それをがっとファイルに出力すればOKでした。
これは簡単!!

package test /** * お試しコントローラー * * @author nakawakashigeto * */ class LocalOutController { def index() { outfilelocal() } def outfilelocal() { // ファイル出力パス def outFile = new File('/Users/nakawakashigeto/tmp/outfilelocal.html') // レンダリング結果を一時変数に def s = g.render template:"/shared/template",model:[abc:"OK7"] // println s // ローカルファイル出力 outFile.withOutputStream{ BufferedOutputStream output -> output.write(s.toString().bytes) } // ブラウザに返す render s } }

: