春ブーツペブルを統合

何ですか

ペブルは小枝に触発されたJavaのテンプレートエンジンです。これは、テンプレートの継承と読みやすい構文を備え、内蔵セキュリティのための自動エスケープに付属し、国際化のための統合サポートが含まれています。

ペブルは、Javaが小枝のテンプレートエンジンに触発です。これは、組み込みのセキュリティ自動エスケープ読みやすいとテンプレートの継承構文を持ち、国際化のための統合サポートが含まれています。

小枝は、非常に人気の高いPHPのテンプレートエンジンである、広く多くのPHPフレームワークを使用しています。構文はまた、テンプレートエンジンジャンゴのpythonで見ることができます。

頼ります

<dependency>
	<groupId>io.pebbletemplates</groupId>
   <artifactId>pebble-spring-boot-starter</artifactId>
	<version>3.0.5</version>
</dependency>
复制代码

使用

 @RequestMapping("/hello")
    public String hello() {
        PebbleEngine engine = new PebbleEngine.Builder().build();
        PebbleTemplate compiledTemplate = engine.getTemplate("templates/home.html");
        Writer writer = new StringWriter();

        Map<String, Object> context = new HashMap<>();
        context.put("websiteTitle", "My First Website");
        context.put("content", "My Interesting Content");

        try {
            compiledTemplate.evaluate(writer, context);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        String output = writer.toString();
        return output;
    }
复制代码

テンプレートファイルの追加

<!DOCTYPE html>
<h1>{{content}}</h1>
</html>
复制代码

もはや見られないThymeleaf出力変数はタグ内の属性に書き込まれるよう。

静的リソース

mvc:
    static-path-pattern: /static/**
复制代码

おすすめ

転載: juejin.im/post/5e1ed2d16fb9a02fe654ad95