动态gsp模板是在我的控制器中创建的,它在开发环境中可以很好地工作,但是在生产环境中不能工作。像这样的代码:
def index() {
def k = Math.round(Math.random() * 100)
def nowPath = this.class.getResource("/").getPath()
def controllerName = this.controllerName
def fileName = "${nowPath}${controllerName}/_${k}.gsp"
def viewString = new StringWriter()
def builder = new MarkupBuilder(viewString)
builder.setDoubleQuotes(true)
builder.div(id: "create-dataItem", class: "content scaffold-create", role: "main") {
"g:uploadForm"(controller: "operation4Data", action: "saveDataItem") {
h1("第${k}次测试")
h1("test:\${test}")
}
def outString = viewString.toString()
def printer = new File(fileName).newPrintWriter('utf-8') //写入文件
printer.println(outString.toString())
printer.close()
def test = new Date()
def view = "${k}"
render(template: "${view}", model: [test: test, k: k])
}
}
答案 0 :(得分:0)
在开发模式下它可以工作,因为grails会根据您的更改(控制器,服务,gsps等)动态更新应用程序
我不确定您的需求,但也许您只是想动态呈现控制器的响应而无需模板。可能是该文档的part(呈现响应部分)
render {
for (b in books) {
div(id: b.id, b.title)
}
}