当我尝试使用groovy生成一个html时,我得到了这个额外的值,这是我的代码和输出
代码:
import groovy.xml.MarkupBuilder
println("let us try a HTML page..\n")
def mkp= new MarkupBuilder()
mkp.html{head{ title "bijoy's groovy"
body{
div{style:"color:red"}
{p "this is cool"}
}}}
并且输出有grrovyTest $ _run_closure1_closure3_closure4_closure5 @ 4d1abd作为额外..如何删除它?
<html>
<head>
<title>bijoy's groovy</title>
<body>
<div>grrovyTest$_run_closure1_closure3_closure4_closure5@4d1abd
<p>this is cool</p>
</div>
</body>
</head>
</html>
答案 0 :(得分:2)
()
中提到了DOM元素的属性,其地图表示如下所示<div>
。
import groovy.xml.MarkupBuilder
println("let us try a HTML page..\n")
def writer = new StringWriter()
def mkp = new MarkupBuilder(writer)
mkp.html{
head{
title "bijoy's groovy"
}
body{
div(style:"color:red"){
p "this is cool"
}
}
}
println writer
另请注意,我已纠正head
和body
并添加了writer
。我想你不希望html body
里面有head
。 :)