Skip to content

Commit b49ad4e

Browse files
Merge pull request eugenp#2552 from eugenp/Refactor_mustache
Refactor mustache
2 parents 1afa7e2 + 159f918 commit b49ad4e

2 files changed

Lines changed: 13 additions & 20 deletions

File tree

‎spring-mustache/src/main/java/com/baeldung/springmustache/SpringMustacheApplication.java‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.baeldung.springmustache;
22

3+
import com.samskivert.mustache.Mustache;
34
import org.springframework.boot.SpringApplication;
45
import org.springframework.boot.autoconfigure.SpringBootApplication;
56
import org.springframework.boot.autoconfigure.mustache.MustacheEnvironmentCollector;
67
import org.springframework.context.annotation.Bean;
78
import org.springframework.context.annotation.ComponentScan;
89
import org.springframework.core.env.Environment;
910

10-
import com.samskivert.mustache.Mustache;
11-
1211
@SpringBootApplication
1312
@ComponentScan(basePackages = {"com.baeldung"})
1413
public class SpringMustacheApplication {
@@ -23,11 +22,10 @@ public Mustache.Compiler mustacheCompiler(Mustache.TemplateLoader templateLoader
2322
MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
2423
collector.setEnvironment(environment);
2524

26-
Mustache.Compiler compiler = Mustache.compiler()
25+
return Mustache.compiler()
2726
.defaultValue("Some Default Value")
2827
.withLoader(templateLoader)
2928
.withCollector(collector);
30-
return compiler;
3129

3230
}
3331
}

‎spring-mustache/src/main/java/com/baeldung/springmustache/controller/ArticleController.java‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
package com.baeldung.springmustache.controller;
22

3-
import java.util.HashMap;
4-
import java.util.LinkedList;
5-
import java.util.List;
6-
import java.util.Map;
7-
import java.util.TreeMap;
8-
import java.util.stream.IntStream;
9-
3+
import com.baeldung.springmustache.model.Article;
104
import org.fluttercode.datafactory.impl.DataFactory;
11-
import org.springframework.beans.factory.annotation.Value;
125
import org.springframework.stereotype.Controller;
13-
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.GetMapping;
147
import org.springframework.web.servlet.ModelAndView;
158

16-
import com.baeldung.springmustache.model.Article;
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
import java.util.stream.Collectors;
13+
import java.util.stream.IntStream;
1714

1815
@Controller
1916
public class ArticleController {
2017

21-
@RequestMapping("/article")
18+
@GetMapping("/article")
2219
public ModelAndView displayArticle(Map<String, Object> model) {
2320

24-
List<Article> articles = new LinkedList<>();
25-
IntStream.range(0, 10)
26-
.forEach(count -> {
27-
articles.add(generateArticle("Article Title " + count));
28-
});
21+
List<Article> articles = IntStream.range(0, 10)
22+
.mapToObj(i -> generateArticle("Article Title " + i))
23+
.collect(Collectors.toList());
2924

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

0 commit comments

Comments
 (0)