0

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

1 回答 1

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. 我想你不想body在 html 里面head。:)

于 2013-10-07T14:19:26.897 回答