th:bold preprocessor thymleaf code example
Example 1: how to use thymeleaf in html
// Add xmlns:th="http://www.thymeleaf.org" into the html opening tag like
<html lang="en" xmlns:th="http://www.thymeleaf.org">
Example 2: write comment in thymeleaf text template
Map<String,String> tokens = new HashMap<String,String>();
tokens.put("cat", "Garfield");
tokens.put("beverage", "coffee");
String template = "%cat% really needs some %beverage%.";
// Create pattern of the format "%(cat|beverage)%"
String patternString = "%(" + StringUtils.join(tokens.keySet(), "|") + ")%";
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(template);
StringBuffer sb = new StringBuffer();
while(matcher.find()) {
matcher.appendReplacement(sb, tokens.get(matcher.group(1)));
}
matcher.appendTail(sb);
System.out.println(sb.toString());