def writer = new StringWriter()
def markup = new groovy.xml.MarkupBuilder(writer)
markup.html {
head {
title('Approval')
}
body {
mkp.yieldUnescaped('Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email')
p ('Regards,')
img(alt: 'your alt text', src: 'your image url')
p ('YamunaS')
}
}
writer.toString()
这将导致:
<html>
<head>
<title>Approval</title>
</head>
<body>Approval is required. Please provide acceptance<br/>Visit the below link to approval/decline<br/><br/>Note This is system generated email
<p>Regards,</p>
<img alt='your alt text' src='your image url' />
<p>YamunaS</p>
</body>
</html>
1条答案
按热度按时间mf98qq941#
您知道Groovy MarkupBuilder(https://docs.groovy-lang.org/latest/html/api/groovy/xml/MarkupBuilder.html)吗?
我会这样回答你的问题:
这将导致:
然后呈现:
如果你也想把第一句/第一行放到一个段落或div容器中,只要按照上面的方法。一个div容器将再次打开一个新的闭包。要获得一个完整的例子,包括一些样式表,你也可以看看我的一个例子。它动态地生成html并在Springboot的上下文中使用它(现在对你来说可能太多了)