我已保存在Oracle數據庫中的BLOB字段,下面的代碼基本上HTML和用SQL嵌入的Groovy代碼,返回一些值渲染BLOB內容爲代碼,而不是文本
<%
import groovy.sql.Sql
def sql = Sql.newInstance("jdbc:mysql://localhost:3306/myDB","root", "root", "com.mysql.jdbc.Driver")
%>
<html>
<head>
<title>Database Example</title>
</head>
<body>
<table align="center" border="1">
<tr>
<td>Id</td>
<td>LastName</td>
<td>FirstName</td>
</tr>
<% sql.eachRow("select profile_id profileId, last_name lastName, first_name firstName from profile") {profile-> %>
<tr>
<td>${profile.profileId}</td>
<td>${profile.lastName}</td>
<td>${profile.firstName}</td>
</tr>
<% } %>
</table>
</body>
</html>
現在我有在變量thistemplate.contents,而我試圖對renderthistemplate.gsp呈現如下圖所示上述BLOB值:
def renderString= g.render(template:"myController/renderthistemplate",model:[rendertemplate:thistemplate.contents])
現在在普惠制我只是做${rendertemplate}
打印整個BLOB。 預期它應該執行整個blob作爲代碼並呈現輸出。 但它實際上將blob的內容作爲普通字符串打印,無論是HTML還是Groovy代碼都在目標GSP中執行。 怎樣纔可以有目標GSP實際呈現的BLOB內容的代碼,而不是作爲字符串/文本 感謝 Priyank
感謝fo提示和參考,我們會試試這個! – 2012-03-07 09:59:41
只是有一個問題,這個調用會每次創建一個新的模板gsp ..取決於blobasString – 2012-03-07 10:16:18
當然;它不是一個完整的GSP,而是從'.gsp'文件構建模板的代碼。還應該如何編譯和運行blob中的Groovy代碼?如果這是性能問題,我建議您在啓動應用程序時創建一次模板,然後在該共享模板上調用'make()'。 – 2012-03-07 17:19:19