html <html> <head> <title><<title>></title> </head> <body> <h1>Welcome, <<name>>!</h1> <p>Your balance is $<<balance>>.</p> </body> </html> public class User { private String name; private double balance; public String getName() { return name; } public double getBalance() { return balance; } } <dependency> <groupId>org.antlr</groupId> <artifactId>stringtemplate</artifactId> <version>4.0.2</version> </dependency> String templateFile = "path/to/myTemplate.st"; StringTemplateGroup templates = new StringTemplateGroup("myGroup", templateFile); StringTemplate template = templates.getInstanceOf("myTemplate"); template.setAttribute("title", "My Website"); template.setAttribute("name", "John Doe"); template.setAttribute("balance", 1000.0); String output = template.toString(); System.out.println(output); html <html> <head> <title>My Website</title> </head> <body> <h1>Welcome, John Doe!</h1> <p>Your balance is $1000.0.</p> </body> </html>


上一篇:
下一篇:
切换中文