Thymeleaf 3.0を試す
長いのかったるいのでシンプルにいきます。面倒な設定もなしです。IDEやビルドシステムすらいらないレベルでさくさくといきます。
ダウンロード
https://bintray.com/thymeleaf/downloads/thymeleaf/view
ここの下のほうにあるthymeleaf-3.0.0.RELEASE-dist.zipとかいうファイルをダウンロードします。
zipの中のlibフォルダにあるjarとdistフォルダにあるthymeleaf-3.0.0.RELEASE.jarをライブラリに追加します。
各自IDEにあわせて設定してください。
コード
import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.thymeleaf.TemplateEngine; import org.thymeleaf.context.Context; import org.thymeleaf.context.IContext; public class Thymeleaf3 { public static void main(String[] args) { //準備 TemplateEngine engine = new TemplateEngine(); //テンプレート String template = "ぼくは[[${hoge}]]ではありません。"; //パラメータ Map<String, Object> params = new HashMap<>(); params.put("hoge", "変態"); IContext context = new Context(Locale.getDefault(), params); //生成 String result = engine.process(template, context); //出力 System.out.println(result); } }
実行結果
ぼくは変態ではありません
おわり。