├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── hellokoding
│ └── springboot
│ ├── HelloController.java
│ └── WebApplication.java
└── resources
├── application.properties
├── static
├── css
│ └── main.css
└── js
│ └── main.js
└── templates
├── hello.ftl
└── index.ftl
/.gitignore:
--------------------------------------------------------------------------------
1 | target
2 | out
3 | .settings
4 | .classpath
5 | .project
6 | .idea
7 | *.iml
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Hello Koding
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring Boot Hello World Example with FreeMarker
2 |
3 | ## Guide
4 | https://hellokoding.com/spring-boot-hello-world-example-with-freemarker/
5 |
6 | ## What you'll need
7 | - JDK 1.7 or later
8 | - Maven 3 or later
9 |
10 | ## Stack
11 | - Spring Boot
12 | - Java
13 |
14 | ## Run
15 | `mvn spring-boot:run`
16 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | hello-springboot
5 | hello-springboot
6 | hello-springboot
7 |
8 | org.springframework.boot
9 | spring-boot-starter-parent
10 | 1.5.8.RELEASE
11 |
12 |
13 |
14 | 1.7
15 |
16 |
17 |
18 |
19 | org.springframework.boot
20 | spring-boot-starter-freemarker
21 |
22 |
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-maven-plugin
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/src/main/java/com/hellokoding/springboot/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.hellokoding.springboot;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.ui.Model;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 |
8 | @Controller
9 | public class HelloController {
10 | @GetMapping("/")
11 | public String index() {
12 | return "index";
13 | }
14 |
15 | @GetMapping("/hello")
16 | public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) {
17 | model.addAttribute("name", name);
18 | return "hello";
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/main/java/com/hellokoding/springboot/WebApplication.java:
--------------------------------------------------------------------------------
1 | package com.hellokoding.springboot;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class WebApplication {
8 | public static void main(String[] args) throws Exception {
9 | SpringApplication.run(WebApplication.class, args);
10 | }
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.freemarker.template-loader-path: classpath:/templates
2 | spring.freemarker.suffix: .ftl
--------------------------------------------------------------------------------
/src/main/resources/static/css/main.css:
--------------------------------------------------------------------------------
1 | .hello-title{
2 | color: darkgreen;
3 | }
--------------------------------------------------------------------------------
/src/main/resources/static/js/main.js:
--------------------------------------------------------------------------------
1 | (function(){
2 | console.log("Hello World!");
3 | })();
--------------------------------------------------------------------------------
/src/main/resources/templates/hello.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Hello ${name}!
6 |
7 |
8 |
9 | Hello ${name}!
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/main/resources/templates/index.ftl:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Spring Boot Hello World Example with FreeMarker
6 |
7 |
8 |
9 | Spring Boot Hello World Example with FreeMarker
10 |
11 |
12 |
--------------------------------------------------------------------------------