Refactor mustache

This commit is contained in:
Grzegorz Piwowarek 2017-09-03 07:29:50 +02:00
parent 3c4faf999d
commit 159f918806
2 changed files with 13 additions and 20 deletions

View File

@ -1,5 +1,6 @@
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;
@ -7,8 +8,6 @@ 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 {
@ -23,11 +22,10 @@ public class SpringMustacheApplication {
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;
}
}

View File

@ -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);