Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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;

import com.samskivert.mustache.Mustache;

@SpringBootApplication
@ComponentScan(basePackages = {"com.baeldung"})
public class SpringMustacheApplication {
Expand All @@ -23,11 +22,10 @@ public Mustache.Compiler mustacheCompiler(Mustache.TemplateLoader templateLoader
MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
collector.setEnvironment(environment);

Mustache.Compiler compiler = Mustache.compiler()
return Mustache.compiler()
.defaultValue("Some Default Value")
.withLoader(templateLoader)
.withCollector(collector);
return compiler;

}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
package com.baeldung.springmustache.controller;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.IntStream;

import com.baeldung.springmustache.model.Article;
import org.fluttercode.datafactory.impl.DataFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import com.baeldung.springmustache.model.Article;
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 {

@RequestMapping("/article")
@GetMapping("/article")
public ModelAndView displayArticle(Map<String, Object> model) {

List<Article> articles = new LinkedList<>();
IntStream.range(0, 10)
.forEach(count -> {
articles.add(generateArticle("Article Title " + count));
});
List<Article> articles = IntStream.range(0, 10)
.mapToObj(i -> generateArticle("Article Title " + i))
.collect(Collectors.toList());

Map<String, Object> modelMap = new HashMap<>();
modelMap.put("articles", articles);
Expand Down