我有一个域类,其中包含一个包含HTML代码的字符串变量.我想在myxml.gsp上显示此代码.
为此我写了以下代码:
Learn.groovy
public class Learn {
String content = ("<html><head><title>Learning Grails</title>
<body>Grails is fun</body></html>");
}
Run Code Online (Sandbox Code Playgroud)
myxml.gsp
<html>
<head>
<title>Xml Output</title>
</head>
<body>
<p>${learn.content}<p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
然而,它无法获取"内容"的值,得到错误:"Cannot get property 'content' on null object".我做错了什么?有没有更好的方法来实现这一目标?