Mustache with Spring Boot examples
This commit is contained in:
BIN
Spring-Boot/spring-boot-mustache/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
Spring-Boot/spring-boot-mustache/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
1
Spring-Boot/spring-boot-mustache/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
1
Spring-Boot/spring-boot-mustache/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@@ -0,0 +1 @@
|
||||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip
|
||||
54
Spring-Boot/spring-boot-mustache/pom.xml
Normal file
54
Spring-Boot/spring-boot-mustache/pom.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.javadevjournal</groupId>
|
||||
<artifactId>spring-boot-mustache</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>spring-boot-mustache</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.0.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mustache</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.javadevjournal;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class SpringBootMustacheApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SpringApplication.run(SpringBootMustacheApplication.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.javadevjournal.controller;
|
||||
|
||||
import com.javadevjournal.data.Product;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
@Controller
|
||||
public class MustacheController {
|
||||
|
||||
@GetMapping("/products")
|
||||
public String getProducts(Map<String, Object> model){
|
||||
|
||||
List<Product> productList = IntStream.range(0,7).mapToObj(i->getProduct(i)).collect(Collectors.toList());
|
||||
model.put("productList",productList);
|
||||
return "product";
|
||||
}
|
||||
|
||||
private Product getProduct(int i){
|
||||
return new Product(String.valueOf(i),"Product"+i, "Sample Description "+i, 100+i);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.javadevjournal.data;
|
||||
|
||||
public class Product {
|
||||
|
||||
private String code;
|
||||
private String name;
|
||||
private String description;
|
||||
private double price;
|
||||
|
||||
public Product() {
|
||||
}
|
||||
|
||||
public Product(String code, String name, String description, double price) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.price = price;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
public void setPrice(double price) {
|
||||
this.price = price;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#logging.level.root= DEBUG
|
||||
#logging.level.org.springframework.security= DEBUG
|
||||
logging.level.org.springframework.web= DEBUG
|
||||
@@ -0,0 +1,2 @@
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Sample Spring Boot application with Mustache</title>
|
||||
</head>
|
||||
<body>
|
||||
@@ -0,0 +1,11 @@
|
||||
{{>header}}
|
||||
<h1>Mustache with Spring Boot</h1>
|
||||
<div>Product List </div><br /><br />
|
||||
{{#productList}}
|
||||
<b> Product Code: </b>{{code}}<br />
|
||||
<b> Product Name: </b>{{name}}<br />
|
||||
<b> Product Description: </b>{{description}}<br />
|
||||
<b> Product Price: </b>{{price}}<br />
|
||||
<br /><br />
|
||||
{{/productList}}
|
||||
{{>footer}}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.javadevjournal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SpringBootMustacheApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user