Welcome

Welcome at the course of the Spring Boot Training

Below you find the content with links to the different parts of this course

News Flash

21-05-2019
  • Released version v1.3.0

Release notes

v1.3.0 (21-05-2019)
  • Add topic: Add Authorities for having the authorization based on Authority

  • Add first steps for Security using the real DB using BCrypt and DaoAuthenticationProvider (without Authority yet)

  • Some improvements after doing the assignments myself regarding Security

  • Fix role name from BIRDS to API

  • Add topic: 4 (four) levels of query syntax

v1.2.0 (24-03-2019)
  • Create better indexing

  • Move logging intro from additional.adoc ⇒ introduction.adoc

General

Monitoring and Logging

Miscellaneous

Topic: Mustache

What you will learn

In the next section of this tutorial you will learn
  • Why you will want to use Mustache

  • What Mustache is

  • How to implement Mustache

Why: Mustache

Mustache makes it easy to have multiple pages (HTML files) using some shared parts (the head section and the footer are the same)

What: Mustache

Mustache is a template engine

How: Mustache

Templates
  • Templates files live in src/main/resources/templates

  • Template files have the extension .mustache

Using templates in code. In index.mustache to have the header and footer you write ⇒
  • {{>header}}

  • {{>footer}}

Standard html files still are still reachable in src/main/resources/static
Previously the names of the Mustache files had the .html suffix. If you read that on some Internet post you are reading and old post < 2019.
Steps: How: Mustache
Add Maven dependency
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-mustache</artifactId>
</dependency>
Add a header template file in src/main/resources/templates (header.mustache)
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>:: My great website ::</title>
    </head>
    <body>
Remember that this file will be written only once. Remember that you can use this file now everywhere using the Mustache syntax {{>header}}
Add a footer template file (footer.mustache)
        <script src="js/index.js"></script>
    </body>
</html>
Remember that this file will be written only once. Remember that you can use this file now everywhere using the Mustache syntax {{>footer}}
Add an index.mustache file (index.mustache)
{{>header}}

<div>
    and some more standard html
</div>

{{>footer}}
Add an guests.mustache file
{{>header}}

<div>
    and some more standard html
</div>


{{>footer}}
Add an tables.mustache file
{{>header}}

<div>
    and some more standard html
</div>

{{>footer}}
Add a Controller for handling the Spring MVC requests (mandatory)
@Controller
public class HomeController {

    @GetMapping
    public String getHome(){

        return "index";
    }

    @GetMapping("guests")
    public String getGuests(){

        return "guests"; // now guests.mustache file is used
    }

    @GetMapping("tables")
    public String getGuests(){

        return "tables"; // now tables.mustache file is used
    }
}
Explaining
  • This class maps "" to the view index.mustache

  • This class maps guests to the view guests.mustache

  • This class maps tables to the view tables.mustache

You are mandatory to write a Controller when using Mustache. Without a Controller, Mustache will not work!!!

Assignment: Mustache

Target

To get started with Mustache template engine

Roadmap

During this assignment you will refactor your profile page using standard html to a Mustache enabled web application

Steps

Add Mustache template engine using the description above to your application.

Validation
  • Your page(s) only contain ONE header and footer

  • Your page(s) may (and should) contain different bodies for the real content of that page

  • After adding Mustache your profile site is still showing the same content as before.

Summary

Using Mustache you only have to write one head and one footer for all the pages you have in your web-application