diff --git a/mustache/pom.xml b/mustache/pom.xml
index d5d80b58e9..15c0e3a8c7 100644
--- a/mustache/pom.xml
+++ b/mustache/pom.xml
@@ -8,9 +8,11 @@
mustache
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
+ org.springframework.boot
+ spring-boot-starter-parent
+ 1.5.4.RELEASE
+
+
@@ -32,6 +34,28 @@
log4j
${log4j.version}
+
+
+ org.springframework.boot
+ spring-boot-starter-mustache
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.webjars
+ bootstrap
+ 3.3.7
+
+
+ org.fluttercode.datafactory
+ datafactory
+ 0.8
+
+
junit
junit
@@ -41,6 +65,15 @@
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
0.9.2
3.7.0
@@ -52,6 +85,8 @@
3.6.0
2.19.1
+
+ 1.8
\ No newline at end of file
diff --git a/mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java b/mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java
new file mode 100644
index 0000000000..8cdf89d08a
--- /dev/null
+++ b/mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java
@@ -0,0 +1,32 @@
+package com.baeldung.springmustache;
+
+import com.samskivert.mustache.Mustache;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.mustache.MustacheEnvironmentCollector;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.core.env.Environment;
+
+@SpringBootApplication
+@ComponentScan(basePackages = {"com.baeldung"})
+public class SpringMustacheApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringMustacheApplication.class, args);
+ }
+
+ @Bean
+ public Mustache.Compiler mustacheCompiler(Mustache.TemplateLoader templateLoader, Environment environment) {
+
+ MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
+ collector.setEnvironment(environment);
+
+ return Mustache.compiler()
+ .defaultValue("Some Default Value")
+ .withLoader(templateLoader)
+ .withCollector(collector);
+
+ }
+}
+
diff --git a/mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java b/mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java
new file mode 100644
index 0000000000..5fc34c9f07
--- /dev/null
+++ b/mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java
@@ -0,0 +1,43 @@
+package com.baeldung.springmustache.controller;
+
+import com.baeldung.springmustache.model.Article;
+import org.fluttercode.datafactory.impl.DataFactory;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.servlet.ModelAndView;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
+
+@Controller
+public class ArticleController {
+
+ @GetMapping("/article")
+ public ModelAndView displayArticle(Map model) {
+
+ List articles = IntStream.range(0, 10)
+ .mapToObj(i -> generateArticle("Article Title " + i))
+ .collect(Collectors.toList());
+
+ Map modelMap = new HashMap<>();
+ modelMap.put("articles", articles);
+
+ return new ModelAndView("index", modelMap);
+ }
+
+ private Article generateArticle(String title) {
+ Article article = new Article();
+ DataFactory factory = new DataFactory();
+ article.setTitle(title);
+ article.setBody(
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur faucibus tempor diam. In molestie arcu eget ante facilisis sodales. Maecenas porta tellus sapien, eget rutrum nisi blandit in. Mauris tempor auctor ante, ut blandit velit venenatis id. Ut varius, augue aliquet feugiat congue, arcu ipsum finibus purus, dapibus semper velit sapien venenatis magna. Nunc quam ex, aliquet at rutrum sed, vestibulum quis libero. In laoreet libero cursus maximus vulputate. Nullam in fermentum sem. Duis aliquam ullamcorper dui, et dictum justo placerat id. Aliquam pretium orci quis sapien convallis, non blandit est tempus.");
+ article.setPublishDate(factory.getBirthDate().toString());
+ article.setAuthor(factory.getName());
+ return article;
+ }
+}
+
+
diff --git a/mustache/src/main/java/com/baeldung/springmustache/model/Article.java b/mustache/src/main/java/com/baeldung/springmustache/model/Article.java
new file mode 100644
index 0000000000..78b08f877f
--- /dev/null
+++ b/mustache/src/main/java/com/baeldung/springmustache/model/Article.java
@@ -0,0 +1,41 @@
+package com.baeldung.springmustache.model;
+
+public class Article {
+ private String title;
+ private String body;
+ private String author;
+ private String publishDate;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getBody() {
+ return body;
+ }
+
+ public void setBody(String body) {
+ this.body = body;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public String getPublishDate() {
+ return publishDate;
+ }
+
+ public void setPublishDate(String publishDate) {
+ this.publishDate = publishDate;
+ }
+
+}
diff --git a/mustache/src/main/resources/application.properties b/mustache/src/main/resources/application.properties
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/mustache/src/main/resources/templates/error/error.html b/mustache/src/main/resources/templates/error/error.html
new file mode 100644
index 0000000000..fa29db41c4
--- /dev/null
+++ b/mustache/src/main/resources/templates/error/error.html
@@ -0,0 +1,9 @@
+
+
+
+
+
+ Something went wrong: {{status}} {{error}}
+
+
+
\ No newline at end of file
diff --git a/mustache/src/main/resources/templates/index.html b/mustache/src/main/resources/templates/index.html
new file mode 100644
index 0000000000..bda60f9d8f
--- /dev/null
+++ b/mustache/src/main/resources/templates/index.html
@@ -0,0 +1,9 @@
+{{>layout/header}}
+
+ {{>layout/article}}
+
+
+
+
+{{>layout/footer}}
diff --git a/mustache/src/main/resources/templates/layout/article.html b/mustache/src/main/resources/templates/layout/article.html
new file mode 100644
index 0000000000..9d573580d3
--- /dev/null
+++ b/mustache/src/main/resources/templates/layout/article.html
@@ -0,0 +1,8 @@
+
+ {{#articles}}
+
{{title}}
+
{{publishDate}}
+
{{author}}
+
{{body}}
+ {{/articles}}
+
\ No newline at end of file
diff --git a/mustache/src/main/resources/templates/layout/footer.html b/mustache/src/main/resources/templates/layout/footer.html
new file mode 100644
index 0000000000..04f34cac54
--- /dev/null
+++ b/mustache/src/main/resources/templates/layout/footer.html
@@ -0,0 +1,2 @@
+
+