Refactor mustache
This commit is contained in:
parent
3c4faf999d
commit
159f918806
|
@ -1,5 +1,6 @@
|
||||||
package com.baeldung.springmustache;
|
package com.baeldung.springmustache;
|
||||||
|
|
||||||
|
import com.samskivert.mustache.Mustache;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.mustache.MustacheEnvironmentCollector;
|
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.context.annotation.ComponentScan;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import com.samskivert.mustache.Mustache;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan(basePackages = {"com.baeldung"})
|
@ComponentScan(basePackages = {"com.baeldung"})
|
||||||
public class SpringMustacheApplication {
|
public class SpringMustacheApplication {
|
||||||
|
@ -23,11 +22,10 @@ public class SpringMustacheApplication {
|
||||||
MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
|
MustacheEnvironmentCollector collector = new MustacheEnvironmentCollector();
|
||||||
collector.setEnvironment(environment);
|
collector.setEnvironment(environment);
|
||||||
|
|
||||||
Mustache.Compiler compiler = Mustache.compiler()
|
return Mustache.compiler()
|
||||||
.defaultValue("Some Default Value")
|
.defaultValue("Some Default Value")
|
||||||
.withLoader(templateLoader)
|
.withLoader(templateLoader)
|
||||||
.withCollector(collector);
|
.withCollector(collector);
|
||||||
return compiler;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,26 @@
|
||||||
package com.baeldung.springmustache.controller;
|
package com.baeldung.springmustache.controller;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import com.baeldung.springmustache.model.Article;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
import org.fluttercode.datafactory.impl.DataFactory;
|
import org.fluttercode.datafactory.impl.DataFactory;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.stereotype.Controller;
|
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 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
|
@Controller
|
||||||
public class ArticleController {
|
public class ArticleController {
|
||||||
|
|
||||||
@RequestMapping("/article")
|
@GetMapping("/article")
|
||||||
public ModelAndView displayArticle(Map<String, Object> model) {
|
public ModelAndView displayArticle(Map<String, Object> model) {
|
||||||
|
|
||||||
List<Article> articles = new LinkedList<>();
|
List<Article> articles = IntStream.range(0, 10)
|
||||||
IntStream.range(0, 10)
|
.mapToObj(i -> generateArticle("Article Title " + i))
|
||||||
.forEach(count -> {
|
.collect(Collectors.toList());
|
||||||
articles.add(generateArticle("Article Title " + count));
|
|
||||||
});
|
|
||||||
|
|
||||||
Map<String, Object> modelMap = new HashMap<>();
|
Map<String, Object> modelMap = new HashMap<>();
|
||||||
modelMap.put("articles", articles);
|
modelMap.put("articles", articles);
|
||||||
|
|
Loading…
Reference in New Issue