grrovyTest $ _run_closure1_closure3_closure4_closure5 @ 4d1abd在生成html时显示在div下

时间:2013-10-07 04:52:37

标签: groovy

当我尝试使用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>

1 个答案:

答案 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

另请注意,我已纠正headbody并添加了writer。我想你不希望html body里面有head。 :)