If you simply want to render a HTML file from within a controller you can use the text parameter of the render controller methoddef htmlContent = new File('/bar/foo.html').textrender text: htmlContent, contentType:"text/html", encoding:"UTF-8"如果你想在 .gsp 中做同样的事情,你可以写一个标签.类似以下内容(未经测试)应该可以工作:If you want to do the same thing from within a .gsp, you could write a tag. Something like the following (untested) should work:import org.springframework.web.context.request.RequestContextHolderclass HtmlTagLib { static namespace = 'html' def render = {attrs -> def filePath = attrs.file if (!file) { throwTagError("'file' attribute must be provided") } def htmlContent = new File(filePath).text out << htmlContent }}您可以使用<html:render file="/bar/foo.html"/> 这篇关于在 Grails 中渲染 HTML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 21:07
查看更多