diff --git a/spring-mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java b/spring-mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java index addd1fa088..8cdf89d08a 100644 --- a/spring-mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java +++ b/spring-mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java @@ -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; } } diff --git a/spring-mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java b/spring-mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java index b24625e7d5..5fc34c9f07 100644 --- a/spring-mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java +++ b/spring-mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java @@ -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 model) { - List
articles = new LinkedList<>(); - IntStream.range(0, 10) - .forEach(count -> { - articles.add(generateArticle("Article Title " + count)); - }); + List
articles = IntStream.range(0, 10) + .mapToObj(i -> generateArticle("Article Title " + i)) + .collect(Collectors.toList()); Map modelMap = new HashMap<>(); modelMap.put("articles", articles);